It's normal: there are some refactoring between 2.x and 3.x.
If you take a look in the command archetype, you can see:
https://git-wip-us.apache.org/repos/asf?p=karaf.git;a=blob_plain;f=archetypes/command/src/main/resources/archetype-resources/src/main/java/__command__.java;hb=karaf-3.0.x
You should extend OsgiCommandSupport.
Don't forget to import:
org.apache.felix.service.command
You can see the Karaf 3.x command style on Cellar 3.x.
Regards
JB
On 12/31/2014 05:47 PM, Mohammad Shamsi wrote:
Hi,
I've upgraded from karaf 2.x to 3.0.2 (with shell namesapce 1.1) and the
custom commands are not working anymore.
Here is a sample command:
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.AbstractAction;
@Command(scope = "my", name = "list", description = "a sample command")
public class ListCommand extendsAbstractAction {
@Argument(index = 0, name = "arg", description ="a sampleargument",
required = false, multiValued = false)
private Stringarg = null;
protected Object doExecute() throws Exception {
return new String[]{"Given parameter: ",arg == null ? "<not given>"
:arg};
}
}
and the blueprint config:
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
<command>
<action class="my.sample.command.ListCommand" />
</command>
</command-bundle>
and finally the pom config:
<Import-Package>
org.apache.karaf.shell.commands,
org.apache.karaf.shell.console,
*
</Import-Package>
but the command installation fails with following message:
org.osgi.service.blueprint.container.ComponentDefinitionException:
org.osgi.service.blueprint.container.ComponentDefinitionException:Unable to
find a matching factorymethod getScope on class
org.apache.karaf.shell.console.commands.NamespaceHandler forarguments
[my.sample.command.ListCommand] when instanciating bean #recipe-11
at
org.apache.aries.blueprint.di.MapRecipe.internalCreate(MapRecipe.java:115)
at
org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:106)[15:org.apache.aries.blueprint.core:1.4.1]
at
org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)[15:org.apache.aries.blueprint.core:1.4.1]
at
org.apache.aries.blueprint.container.BlueprintRepository.createInstance(BlueprintRepository.java:230)[15:org.apache.aries.blueprint.core:1.4.1]
at
org.apache.aries.blueprint.container.BlueprintRepository.create(BlueprintRepository.java:145)[15:org.apache.aries.blueprint.core:1.4.1]
at
org.apache.aries.blueprint.container.ServiceRecipe.createRecipe(ServiceRecipe.java:440)
at
org.apache.aries.blueprint.container.ServiceRecipe.register(ServiceRecipe.java:165)
Am I missing anything here? any idea?
Thanks
--
Jean-Baptiste Onofré
[email protected]
http://blog.nanthrax.net
Talend - http://www.talend.com