+1 this approach is the same we use
> On Apr 17, 2025, at 11:52 AM, João Assunção <joao.assun...@exploitsys.com>
> wrote:
>
> I checked, and the annotations package are not required during runtime. If I
> use the headers command to list the packages required by a bundle where SCR
> components are used, the package "org.osgi.service.component.annotations" is
> not required.
> In the previous email I forgot to mention that I install the scr feature.
> For karaf shell commands, I don't use SCR. I use Karaf's API for commands.
> Follow a simple command using a service provided by an SCR component. For the
> command to be recognized by Karaf it is necessary to include a header
> "Karaf-Commands:*"in the bundle manifest. I use bnd-maven-plugin to build my
> bundles
>
>> import org.apache.karaf.shell.api.action.Action;
>> import org.apache.karaf.shell.api.action.Argument;
>> import org.apache.karaf.shell.api.action.Command;
>> import org.apache.karaf.shell.api.action.lifecycle.Reference;
>> import org.apache.karaf.shell.api.action.lifecycle.Service;
>>
>> import com.atobe.ort.photo.repository.PhotoRepositoryService;
>>
>> @Command(scope = "photorepo", name = "purge", description = "Purge")
>> @Service
>> public class PurgeCommand implements Action {
>>
>> @Reference
>> PhotoRepositoryService repositoryService;
>>
>> @Argument(index = 0, name = "days", description = "Days", multiValued =
>> false, required = true)
>> Integer days;
>>
>> @Override
>> public Object execute() throws Exception {
>>
>> Duration age = Duration.ofDays(days);
>> repositoryService.purgePhotos(age);
>> return null;
>> }
>>
>> }
>
> The corresponding "bnd.bnd" file:
>> Bundle-Name: ${project.name <http://project.name/>}
>> Bundle-Description: ${project.description}
>> Karaf-Commands:*
>
>
> Best regards,
> João
>
>
>
> On Thu, Apr 17, 2025 at 4:41 PM Ephemeris Lappis <ephemeris.lap...@gmail.com
> <mailto:ephemeris.lap...@gmail.com>> wrote:
>> Hello João !
>>
>> First, thanks for your answer.
>>
>> I see your dependency as "provided", so I suppose that you assume that
>> classes are exported by some bundle. In my case I didn't find any standard
>> feature with a bundle that exports the required annotations packages. What
>> did you do to get them at runtime ?
>>
>> As I aim to provide custom shell commands, I'd initially prefer to use a
>> basic OSGi design, and using annotations, and. with the SCR files being
>> generated by the bundle plugin.
>>
>> An alternate solution could be using Karaf packages, as described in these
>> examples
>> (https://github.com/apache/karaf/blob/main/examples/karaf-command-example/karaf-command-example-command/src/main/java/org/apache/karaf/examples/command/command/AddCommand.java).
>>
>>
>> But this also fails : my custom command is not correctly detected and
>> installed.
>>
>> An idea of the best way to do that ?
>>
>> Thanks again.
>>
>> Regards.
>>
>> Le jeu. 17 avr. 2025 à 13:47, João Assunção <joao.assun...@exploitsys.com
>> <mailto:joao.assun...@exploitsys.com>> a écrit :
>>> Hi,
>>> I'm almost sure the annotations are not needed during execution. During
>>> runtime, SCR uses the XML files included inside the bundle (jar).
>>> The bundle plugin uses the annotation in the classes to generate those xml
>>> descriptors.
>>> In my maven projects, I normally use the "bom" dependency provided by karaf
>>> to ensure I'm using the same dependencies used by Karaf. For example:
>>>> <dependency>
>>>> <groupId>org.apache.karaf</groupId>
>>>> <artifactId>karaf-bom</artifactId>
>>>> <version>${karaf.version}</version>
>>>> <type>pom</type>
>>>> <scope>import</scope>
>>>> </dependency>
>>>
>>> But for my convenience, I tend to use the Enroute dependency:
>>> <dependency>
>>> <groupId>org.osgi.enroute</groupId>
>>> <artifactId>osgi-api</artifactId>
>>> <version>7.0.0</version>
>>> <type>pom</type>
>>> <scope>provided</scope>
>>>> </dependency>
>>>
>>> Best regards,
>>> João
>>>
>>>
>>>
>>>
>>>
>>> On Thu, Apr 17, 2025 at 11:50 AM Ephemeris Lappis
>>> <ephemeris.lap...@gmail.com <mailto:ephemeris.lap...@gmail.com>> wrote:
>>>> Hello.
>>>>
>>>> I can't find if a Karaf feature exists to provide the annotations for SCR,
>>>> such as Service, Reference, etc.
>>>>
>>>> Installing the feature "scr" just adds bundles to manage the runtime, not
>>>> the annotations.
>>>>
>>>> Perhaps the packages are provided by a Compendium bundle.
>>>>
>>>> Is there a provided feature that includes them, or do we have to add
>>>> explicitly bundles for that ? In this case, what is the right version to
>>>> match the OSGi framework of Karaf 4.4.x ?
>>>>
>>>> Thanks for your help.
>>>>
>>>> Regards.