...
Code Block |
---|
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.servicemix.kernelgshell.gshell<samples</groupId>
<artifactId>org.apache.servicemix.kernel.gshell.config</artifactId><artifactId>gshell-commands<artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>org.apache.servicemix.kernel.gshell.config< <name>Hello GShell Example</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
|
...
Code Block |
---|
|
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.02.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.servicemix.kernel.gshell</groupId>
<artifactId>org.apache.servicemix.kernel.gshell.core</artifactId>
<version>1.1.0-m2<SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-core</artifactId>
<version>1.2.0<0-m2</version>
</dependency>
|
These are needed respectively for OSGi, ServiceMix Kernel commands support and Spring-DM.
...
Code Block |
---|
|
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
|
Add the Spring Milestone Repository
Due to the use of the spring-osgi-core milestone version we need to add the repository for that here.
Code Block |
---|
|
<repositories>
<repository>
<id>spring-milestone</id>
<name>Spring Portfolio Milestone Repository</name>
<url>http://s3.amazonaws.com/maven.springframework.org/milestone</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
|
Loading the project in your IDE
...
We can now create the command class ListCommandHelloGShellCommand.java
Code Block |
---|
title | ConfigListHelloGShellCommand.java |
---|
lang | java |
---|
|
package org.apache.servicemix.kernel.gshell.configsample;
import org.apache.servicemix.geronimokernel.gshell.supportcore.OsgiCommandSupport;
import
public class HelloGShellCommand extends OsgiCommandSupport {
/* (non-Javadoc)
* @see org.apache.geronimoservicemix.kernel.gshell.command.annotation.CommandComponent;
@CommandComponent(id="config:list", description="List the available configurations")
public class ListCommand extends OsgiCommandSupport {
core.OsgiCommandSupport#doExecute()
*/
@Override
protected Object doExecute() throws Exception {
io.out.println("Executing ListHello command");
return null;
}
}
|
...
Code Block |
---|
title | gshell-config.xml |
---|
lang | xml |
---|
|
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:gshell="http://servicemix.apache.org/schema/servicemix-gshell"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/utilosgi
http://www.springframework.org/schema/utilosgi/spring-utilosgi.xsd
http://www.springframework.org/schema/osgi-compendium
http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
http://www.springframework.org/schema/osgi-compendiumutil
http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium/util/spring-util.xsd
http://servicemix.apache.org/schema/servicemix-gshell
http://servicemix.apache.org/schema/servicemix-gshell/servicemix-gshell.xsd">
<bean id="list" class <import resource="classpath:org./apache./servicemix./kernel./gshell.config.ListCommand/core/commands.xml" />
<gshell:command-bundle>
<osgi:service ref="list" interface <!-- Commands -->
<gshell:command name="sample/hello">
<gshell:action class="org.apache.geronimoservicemix.gshell.commandsample.CommandHelloGShellCommand" />
<osgi:service-properties> </gshell:command>
<!-- add more commands here -->
<entry key="shell" value="config"/ <!-- Aliases -->
<entry key <gshell:alias name="aliassample/hi" valuealias="listsample/hello" />
</osgi:service-properties> <!-- add more aliases here -->
</osgigshell:service>command-bundle>
</beans>
|
Compiling the jar
...
Code Block |
---|
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
|
Tip |
---|
|
If you see something like that: Code Block |
---|
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
xxx/src/main/java/org/apache/servicemix/kernel/gshell/config/ListCommand.java:[6,1] annotations are not supported in -source 1.3
(try -source 1.5 to enable annotations)
@CommandComponent(id="config:list", description="List the available configurations")
|
that's because we forgot to enable Java 5. So let's add that to the pom: Code Block |
---|
|
|
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-
compiler-
plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Turning the jar into an OSGi bundle
...
Code Block |
---|
|
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>Config</Bundle-SymbolicName>
<Import-Package>org.apache.geronimo.gshell.command,org.apache.servicemix.kernel.gshell.core,*</Import-Package>
<Spring-Context>*;publish-context:=false;create-asynchronously:=false</Spring-Context>
</instructions>
</configuration>
<dependencies>
<dependency>
<groupId>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
|
...
Code Block |
---|
osgi install -s mvn:org.apache.servicemix.kernelgshell.gshell/org.apache.servicemix.kernel.gshell.configsamples/gshell-commands/1.0-SNAPSHOT
|
If you run the help
command, you should now see our new shell config
sample
.
Let's try running the command:
Code Block |
---|
servicemix> sample/hello
Executing Hello command
|
and for the alias:
Code Block |
---|
servicemix> sample/hiconfig list
Executing ListHello command
|
Yeah
#top