You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Steinar Bang <sb...@dod.no> on 2020/01/25 17:55:50 UTC

What's needed to make karaf pick up a command?

What's needed to make karaf pick up a command?

Is it enough to annotate a class implementing the Action interface and
annotate it with the @Command and @Service annotations, and then load
the bundle that contains the class?

Or are there special considerations to make:

The class should not reside in a bundle that does other things  commands?

The package containing the classes should be exported from the bundle?

The command classes should be mentioned in the manifest?

Should the command classes be handled specially in the karaf feature file?

I think at some point this command worked, but it is no longer available
even when the bundle that contains the command is loaded:
 https://github.com/steinarb/ukelonn/blob/master/ukelonn.backend/src/main/java/no/priv/bang/ukelonn/backend/KarafReleaseLiquibaseLockCommand.java#L30

Can anyone spot what might be wrong? (I haven't done anything special
except for adding the class to a bundle that is loaded by a feature and
start a DS component)

Thanks!


Re: What's needed to make karaf pick up a command?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Francois Papon <fr...@openobject.fr>:

> Hi Steinar,
> I think you have to add the karaf-services-maven-plugin in your build:

> https://github.com/apache/karaf/blob/2bc547f5e1a8a681333d40aa291ac3cf615c1d2f/examples/karaf-command-example/karaf-command-example-command/pom.xml#L51

Thanks Francois and JB!

I added a config in the <pluginManagement> of the top pom, and
referenced the plugin in <plugins> of the pom of the maven module
building the bundle containing the command
 https://github.com/steinarb/ukelonn/commit/2210080855cb199d8b0dae11fe9bbf8a0fd2a104

I rebuilt the app, and then the ukelonn:release-liquibase-lock command
was available in the karaf console after installing the ukelonn app:
 karaf@root()> feature:repo-add mvn:no.priv.bang.ukelonn/karaf/LATEST/xml/features
 Adding feature url mvn:no.priv.bang.ukelonn/karaf/LATEST/xml/features
 karaf@root()> feature:install ukelonn-with-derby
 karaf@root()> ukelonn:release-liquibase-lock
 Forcibly unlocked the Liquibase changelog lock
 karaf@root()>




Re: What's needed to make karaf pick up a command?

Posted by Francois Papon <fr...@openobject.fr>.
Hi Steinar,

I think you have to add the karaf-services-maven-plugin in your build:

https://github.com/apache/karaf/blob/2bc547f5e1a8a681333d40aa291ac3cf615c1d2f/examples/karaf-command-example/karaf-command-example-command/pom.xml#L51

regards,

François
fpapon@apache.org

Le 25/01/2020 à 18:55, Steinar Bang a écrit :
> What's needed to make karaf pick up a command?
>
> Is it enough to annotate a class implementing the Action interface and
> annotate it with the @Command and @Service annotations, and then load
> the bundle that contains the class?
>
> Or are there special considerations to make:
>
> The class should not reside in a bundle that does other things  commands?
>
> The package containing the classes should be exported from the bundle?
>
> The command classes should be mentioned in the manifest?
>
> Should the command classes be handled specially in the karaf feature file?
>
> I think at some point this command worked, but it is no longer available
> even when the bundle that contains the command is loaded:
>  https://github.com/steinarb/ukelonn/blob/master/ukelonn.backend/src/main/java/no/priv/bang/ukelonn/backend/KarafReleaseLiquibaseLockCommand.java#L30
>
> Can anyone spot what might be wrong? (I haven't done anything special
> except for adding the class to a bundle that is loaded by a feature and
> start a DS component)
>
> Thanks!
>

Re: What's needed to make karaf pick up a command?

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Hi Paul,

That’s possible. Can you please create a Jira describing the issue, I will take a look, it will be easier.

Regards
JB

> Le 16 juil. 2020 à 02:46, Paul Spencerx <pa...@intekon.com> a écrit :
> 
> JB,
> This response may be in the wrong thread.  I have posted addition information 
>   http://karaf.922171.n3.nabble.com/Question-about-Reference-Karaf-Command-annotation-tp4057824p4058625.html
> 
> Paul Spencer
> 
>> On Jul 15, 2020, at 2:44 PM, Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:
>> 
>> Hi
>> 
>> I added filter support on command reference. And it works for sure. The problem is more in the way you organise the bundle. Do you have scr components and bundles in the same bundle ?
>> 
>> Regards 
>> JB
>> 
>> Le mer. 15 juil. 2020 ? 20:01, Steinar Bang <sb...@dod.no> a ?crit :
>>>>>>> Paul Spencer <pa...@mindspring.com>: 
>> 
>>> From my experience using Karaf 4.2.9 I found the following is needed in POM, or inherited POM. 
>> [snip!] 
>> 
>> Hi Paul, I can't remember offhand but I guess I ended up doing something 
>> like what you describe: 
>> http://karaf.922171.n3.nabble.com/What-s-needed-to-make-karaf-pick-up-a-command-tp4057480p4057483.html 
>> 
> 


Re: What's needed to make karaf pick up a command?

Posted by Paul Spencerx <pa...@intekon.com>.
JB,
This response may be in the wrong thread.  I have posted addition information 
   http://karaf.922171.n3.nabble.com/Question-about-Reference-Karaf-Command-annotation-tp4057824p4058625.html

Paul Spencer

> On Jul 15, 2020, at 2:44 PM, Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:
> 
> Hi
> 
> I added filter support on command reference. And it works for sure. The problem is more in the way you organise the bundle. Do you have scr components and bundles in the same bundle ?
> 
> Regards 
> JB
> 
> Le mer. 15 juil. 2020 ? 20:01, Steinar Bang <sb...@dod.no> a ?crit :
> >>>>> Paul Spencer <pa...@mindspring.com>: 
> 
> > From my experience using Karaf 4.2.9 I found the following is needed in POM, or inherited POM. 
> [snip!] 
> 
> Hi Paul, I can't remember offhand but I guess I ended up doing something 
> like what you describe: 
> http://karaf.922171.n3.nabble.com/What-s-needed-to-make-karaf-pick-up-a-command-tp4057480p4057483.html 
> 


Re: What's needed to make karaf pick up a command?

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi

  

I added filter support on command reference. And it works for sure. The
problem is more in the way you organise the bundle. Do you have scr components
and bundles in the same bundle ?

  

Regards

JB

  

Le mer. 15 juil. 2020 ? 20:01, Steinar Bang <sb...@dod.no> a ?crit :  

> >>>>> Paul Spencer <pa...@mindspring.com>:  
>  
> > From my experience using Karaf 4.2.9 I found the following is needed in
POM, or inherited POM.  
> [snip!]  
>  
> Hi Paul, I can't remember offhand but I guess I ended up doing something  
> like what you describe:  
>  http://karaf.922171.n3.nabble.com/What-s-needed-to-make-karaf-pick-up-a-
command-tp4057480p4057483.html  
>  
>


Re: What's needed to make karaf pick up a command?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Paul Spencer <pa...@mindspring.com>:

> From my experience using Karaf 4.2.9 I found the following is needed in POM, or inherited POM.  
[snip!]

Hi Paul, I can't remember offhand but I guess I ended up doing something
like what you describe:
 http://karaf.922171.n3.nabble.com/What-s-needed-to-make-karaf-pick-up-a-command-tp4057480p4057483.html


Re: What's needed to make karaf pick up a command?

Posted by Paul Spencer <pa...@mindspring.com>.
From my experience using Karaf 4.2.9 I found the following is needed in POM, or inherited POM.  

   </build>
      </pluginManagement>
        </plugins>
          <plugin>
             <groupId>org.apache.karaf.tooling</groupId>
             <artifactId>karaf-services-maven-plugin</artifactId>
             <version>4.2.9</version>
             <executions>
               <execution>
                 <id>service-metadata-generate</id>
                 <phase>process-classes</phase>
                 <goals>
                   <goal>service-metadata-generate</goal>
                 </goals>
               </execution>
             </executions>
          </plugin>
        </plugins>
      </pluginManagement>
   </build>

Section 3.2 of the Karaf documentation, http://karaf.apache.org/manual/latest/#_commands, contains the following, but nowhere mentions the configuration for the goal service-metadata-generate.  

> However, in Karaf 4.x, you can use DS and new annotations and avoid the usage of a blueprint XML.
> 
> The new annotations are available: @Service, @Completion, @Parsing, @Reference. It allows you to completely define the command in the command class directly.
> 
> To simplify the generation of the code and OSGi headers, Karaf 4.x provides the karaf-services-maven-plugin (in org.apache.karaf.tooling Maven groupId).
> 
> Take a look in the developer guide for the command development "new style" details.

When looking through the examples in the source, you find the configuration in the buried in Karaf's root pom, https://github.com/apache/karaf/blob/master/pom.xml#L2054

I would expect the following:
- Section on karaf-services-maven-plugin in the Developer section of the Karaf documentation
- Reference to karaf-services-maven-plugin in the appropriate example code documentation
      https://github.com/apache/karaf/tree/master/examples/karaf-command-example


Paul Spencer


> On Jan 25, 2020, at 1:30 PM, jb@nanthrax.net wrote:
> 
> Hi
> 
> Do you have the karaf service plugin in your pom ?
> It's this plugin which converts annotations to services.
> Take a look on the karaf-command-example.
> 
> Regards
> JB
> 
> Le 25 janv. 2020 18:55, Steinar Bang <sb...@dod.no> a écrit :
> What's needed to make karaf pick up a command?
> 
> 
> Is it enough to annotate a class implementing the Action interface and
> annotate it with the @Command and @Service annotations, and then load
> the bundle that contains the class?
> 
> Or are there special considerations to make:
> The class should not reside in a bundle that does other things  commands?
> 
> The package containing the classes should be exported from the bundle?
> 
> The command classes should be mentioned in the manifest?
> 
> Should the command classes be handled specially in the karaf feature file?
> 
> I think at some point this command worked, but it is no longer available
> even when the bundle that contains the command is loaded:
> https://github.com/steinarb/ukelonn/blob/master/ukelonn.backend/src/main/java/no/priv/bang/ukelonn/backend/KarafRele
> aseLiquibaseLockCommand.java#L30
> 
> Can anyone spot what might be wrong? (I haven't done anything special
> except for adding the class to a bundle that is loaded by a feature and
> start a DS component)
> 
> Thanks!
> 


Re: What's needed to make karaf pick up a command?

Posted by jb...@nanthrax.net.
Hi

  

Do you have the karaf service plugin in your pom ?

It's this plugin which converts annotations to services.

Take a look on the karaf-command-example.

  

Regards

JB

  

Le 25 janv. 2020 18:55, Steinar Bang <sb...@dod.no> a écrit :  

> What's needed to make karaf pick up a command?  
>  
>  Is it enough to annotate a class implementing the Action interface and  
>  annotate it with the @Command and @Service annotations, and then load  
>  the bundle that contains the class?  
>  
>  Or are there special considerations to make:  
>  
>  The class should not reside in a bundle that does other things  commands?  
>  
>  The package containing the classes should be exported from the bundle?  
>  
>  The command classes should be mentioned in the manifest?  
>  
>  Should the command classes be handled specially in the karaf feature file?  
>  
>  I think at some point this command worked, but it is no longer available  
>  even when the bundle that contains the command is loaded:  
>
https://github.com/steinarb/ukelonn/blob/master/ukelonn.backend/src/main/java/no/priv/bang/ukelonn/backend/KarafReleaseLiquibaseLockCommand.java#L30  
>  
>  Can anyone spot what might be wrong? (I haven't done anything special  
>  except for adding the class to a bundle that is loaded by a feature and  
>  start a DS component)  
>  
>  Thanks!  
>  
>