SeamFramework.orgCommunity Documentation
In this chapter you will see:
how to setup the environment in order to use Weld-OSGi
how to build your first bean bundle using CDI in OSGi
how to build a more complex example with advanced CDI usage
Weld-OSGi may run in an OSGi environment, you should setup one:
Download the last version of Felix framework here: http://felix.apache.org/site/downloads.cgi
Extract the files anywhere you want, this location will be called the Felix home
Open a terminal in the Felix home and run the Felix framework with
java -jar bin/felix.jar
You should now have a running OSGi environment with the Felix framework prompt:
____________________________ Welcome to Apache Felix Gogo g!
Try your Felix installation a bit with these three main command:
The lb
command, that lists all the bundles in the OSGi
environment, with their id and state (currently you only have the Felix
framework utility
bundles)
g! lb START LEVEL 1 ID|State |Level|Name 0|Active | 0|System Bundle (3.2.2) 1|Active | 1|Apache Felix Bundle Repository (1.6.2) 2|Active | 1|Apache Felix Gogo Command (0.8.0) 3|Active | 1|Apache Felix Gogo Runtime (0.8.0) 4|Active | 1|Apache Felix Gogo Shell (0.8.0) g!
The stop <bundle_id>
command, that stops the corresponding
bundle
g! stop 1 g! lb START LEVEL 1 ID|State |Level|Name 0|Active | 0|System Bundle (3.2.2) 1|Resolved | 1|Apache Felix Bundle Repository (1.6.2) 2|Active | 1|Apache Felix Gogo Command (0.8.0) 3|Active | 1|Apache Felix Gogo Runtime (0.8.0) 4|Active | 1|Apache Felix Gogo Shell (0.8.0) g!
The start <bundle_id>
command, that starts the
corresponding
bundle
g! start 1 g! lb START LEVEL 1 ID|State |Level|Name 0|Active | 0|System Bundle (3.2.2) 1|Active | 1|Apache Felix Bundle Repository (1.6.2) 2|Active | 1|Apache Felix Gogo Command (0.8.0) 3|Active | 1|Apache Felix Gogo Runtime (0.8.0) 4|Active | 1|Apache Felix Gogo Shell (0.8.0) g!
Felix framework currently auto start all bundles, although it is a good thing for
utility bundles it may be inconvenient with application bundles. You should configure
the Felix framework by editing the Felix home conf/config.properties
file:
Unable the auto start option by replacing the line
felix.auto.deploy.action=install,start
by
#felix.auto.deploy.action=install,start
Ask for auto start of utility bundle by replacing the line
#felix.auto.start.1=
by
felix.auto.start.1= file:bundle/org.apache.felix.bundlerepository-1.6.2.jar \ file:bundle/org.apache.felix.gogo.command-0.8.0.jar \ file:bundle/org.apache.felix.gogo.runtime-0.8.0.jar \ file:bundle/org.apache.felix.gogo.shell-0.8.0.jar
Install Weld-OSGi in the Felix framework:
Add some bundle in the Felix framework by simply drop the corresponding
jar
files into the bundle
directory of Felix
home
Download the last version of Weld-OSGi here: TBA
Extract the five bundles into the bundle
directory of Felix
home
Felix framework keeps a cache of old bundles and actions you
performed. You may remove the Felix home felix-cache
directory to avoid older versions of bundle and configuration to be
taken into account when:
You add/remove bundles from bundle
directory
You modify the conf/config.properties
file
You restart the Felix framework after running some commands
Update the Felix framework configuration file in order to auto install the Weld-OSGi bundle by replacing the line
#felix.auto.install.1=
by
felix.auto.install.1= file:bundle/weld-osgi-core-api-1.0-SNAPSHOT.jar \ file:bundle/weld-osgi-core-extension-1.0-SNAPSHOT.jar \ file:bundle/weld-osgi-core-spi-1.0-SNAPSHOT.jar \ file:bundle/weld-osgi-core-mandatory-1.0-SNAPSHOT.jar \ file:bundle/weld-osgi-core-integration-1.0-SNAPSHOT.jar
Check the bundle are in the OSGi environment by starting the Felix framework
____________________________ Welcome to Apache Felix Gogo g! lb START LEVEL 1 ID|State |Level|Name 0|Active | 0|System Bundle (3.2.2) 1|Active | 1|Apache Felix Bundle Repository (1.6.2) 2|Active | 1|Apache Felix Gogo Command (0.8.0) 3|Active | 1|Apache Felix Gogo Runtime (0.8.0) 4|Active | 1|Apache Felix Gogo Shell (0.8.0) 5|Installed | 1|Weld-OSGi :: Core :: Extension API (1.0.0.SNAPSHOT) 6|Installed | 1|Weld-OSGi :: Core :: Extension Impl (1.0.0.SNAPSHOT) 7|Installed | 1|Weld-OSGi :: Core :: Integration API (1.0.0.SNAPSHOT) 8|Installed | 1|Weld-OSGi :: Core :: Mandatory (1.0.0.SNAPSHOT) 9|Installed | 1|Weld-OSGi :: Implementation :: Weld Integration (1.0.0.SNAPSHOT) g!
Run the bundles Weld-OSGi :: Core :: Extension Impl
and
Weld-OSGi :: Implementation :: Weld Integration
in order to
get the Weld-OSGi running in the Felix
framework
g! start 6 g! start 9 g! lb START LEVEL 1 ID|State |Level|Name 0|Active | 0|System Bundle (3.2.2) 1|Active | 1|Apache Felix Bundle Repository (1.6.2) 2|Active | 1|Apache Felix Gogo Command (0.8.0) 3|Active | 1|Apache Felix Gogo Runtime (0.8.0) 4|Active | 1|Apache Felix Gogo Shell (0.8.0) 5|Resolved | 1|Weld-OSGi :: Core :: Extension API (1.0.0.SNAPSHOT) 6|Active | 1|Weld-OSGi :: Core :: Extension Impl (1.0.0.SNAPSHOT) 7|Resolved | 1|Weld-OSGi :: Core :: Integration API (1.0.0.SNAPSHOT) 8|Resolved | 1|Weld-OSGi :: Core :: Mandatory (1.0.0.SNAPSHOT) 9|Active | 1|Weld-OSGi :: Implementation :: Weld Integration (1.0.0.SNAPSHOT) g!
It would be easier if these two bundles were auto started with Felix framework.
Modify the Felix configuration file to do so
felix.auto.install.1= file:bundle/weld-osgi-core-api-1.0-SNAPSHOT.jar \ file:bundle/weld-osgi-core-spi-1.0-SNAPSHOT.jar \ file:bundle/weld-osgi-core-mandatory-1.0-SNAPSHOT.jar ... felix.auto.start.1= file:bundle/org.apache.felix.bundlerepository-1.6.2.jar \ file:bundle/org.apache.felix.gogo.command-0.8.0.jar \ file:bundle/org.apache.felix.gogo.runtime-0.8.0.jar \ file:bundle/org.apache.felix.gogo.shell-0.8.0.jar \ file:bundle/weld-osgi-core-extension-1.0-SNAPSHOT.jar \ file:bundle/weld-osgi-core-integration-1.0-SNAPSHOT.jar
Try this new configuration
____________________________ Welcome to Apache Felix Gogo g! lb START LEVEL 1 ID|State |Level|Name 0|Active | 0|System Bundle (3.2.2) 1|Active | 1|Apache Felix Bundle Repository (1.6.2) 2|Active | 1|Apache Felix Gogo Command (0.8.0) 3|Active | 1|Apache Felix Gogo Runtime (0.8.0) 4|Active | 1|Apache Felix Gogo Shell (0.8.0) 5|Active | 1|Weld-OSGi :: Core :: Extension Impl (1.0.0.SNAPSHOT) 6|Active | 1|Weld-OSGi :: Implementation :: Weld Integration (1.0.0.SNAPSHOT) 7|Resolved | 1|Weld-OSGi :: Core :: Extension API (1.0.0.SNAPSHOT) 8|Resolved | 1|Weld-OSGi :: Core :: Integration API (1.0.0.SNAPSHOT) 9|Resolved | 1|Weld-OSGi :: Core :: Mandatory (1.0.0.SNAPSHOT) g!
It is time to test your installation with your first application bean bundle. The goal
here is to provide a "Hello World!" (and "Goodbye World!") service and use CDI to inject
it into the main class of your bean bundle. It will be the hello-world
bundle.
First you need to write down the "Hello World!" service:
The com.sample.api.HelloWorld.java
interface
package com.sample.api; public interface HelloWorld { void sayHello(); void sayGoodbye(); }
The com.sample.impl.HelloWorldImpl.java
implementation
class
package com.sample.impl; import com.sample.api.HelloWorld; public class HelloWorldImpl implements HelloWorld { @Override public void sayHello() { System.out.println("Hello World!"); } @Override public void sayGoodbye() { System.out.println("Goodbye World!"); } }
Nothing fancy here.
Next you need to write the entry point of your application (i.e the main class of the
bean bundle). That is the com.sample.App.java
main
class
package com.sample; import com.sample.api.HelloWorld; (1) import org.osgi.cdi.api.extension.events.BundleContainerEvents; (2) import javax.enterprise.event.Observes; import javax.inject.Inject; public class App { @Inject (3) HelloWorld helloWorld; public void onStartup(@Observes BundleContainerEvents.BundleContainerInitialized event) { (4) helloWorld.sayHello(); } public void onShutdown(@Observes BundleContainerEvents.BundleContainerShutdown event) { (5) helloWorld.sayGoodbye(); } }
You
import your service interface (1) and the CDI and
Weld-OSGi dependencies (2). You ask CDI for an
injection of the HelloWorld
service (3).
onStartup
method(4) and
onShutdown
method (5) are called when
CDI usage is enable for the bean bundle (4) (i.e the
bean bundle application can start) or when CDI usage is disable for the bean bundle
(5) (i.e the bean bundle application may
stop).
Finally you should write the configuration files of your bean bundle:
The pom.xml
Maven configuration
file
<?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sample</groupId> <artifactId>hello-world</artifactId> <version>1.0</version> <packaging>bundle</packaging> (1) <dependencies> (2) <dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> </dependency> <dependency> <groupId>javax.enterprise</groupId> <artifactId>cdi-api</artifactId> <version>1.0-SP4</version> </dependency> <dependency> <groupId>org.osgi.cdi</groupId> <artifactId>weld-osgi-core-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> (3) <extensions>true</extensions> <configuration> <instructions> <_include>-target/classes/META-INF/${project.artifactId}.bnd</_include> (4) </instructions> </configuration> </plugin> </plugins> </build> </project>
You
setup the dependencies for the com.sample.App.java
main class
(2). You say that Maven may build an
OSGi bundle (1) using the
maven-bundle-plugin
(3) with the
META-INF/hello-world.bnd
(4) configuration file.
The META-INF\beans.xml
CDI marker
file
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> </beans>
This
is an empty beans.xml
file that only tells the bundle is a bean
bundle (i.e Weld-OSGi may managed it).
The META-INF\hello-world.bnd
OSGi configuration
file
# Let bnd handle the MANIFEST.MF generation
The
bnd tool will generate the OSGi MANIFEST.MF
configuration file
just fine for this simple example.
Your project should now looks like that:
hello-world pom.xml - src - main - java - com.sample App.java - api HelloWorld.java - impl HelloWorldImpl.java - resources - META-INF beans.xml hello-world.bnd
It is time to try out this first bean bundle:
Build your project using Maven: mvn clean install
Copy the generated hello-world-1.0.jar
file to the Felix home
bundle
directory
Update the Felix configuration file to auto install the bean bundle
felix.auto.install.1= file:bundle/weld-osgi-core-api-1.0-SNAPSHOT.jar \
file:bundle/weld-osgi-core-spi-1.0-SNAPSHOT.jar \
file:bundle/weld-osgi-core-mandatory-1.0-SNAPSHOT.jar \
file:bundle/hello-world-1.0.jar
Start the Felix framework
____________________________
Welcome to Apache Felix Gogo
g! lb
START LEVEL 1
ID|State |Level|Name
0|Active | 0|System Bundle (3.2.2)
1|Active | 1|Apache Felix Bundle Repository (1.6.2)
2|Active | 1|Apache Felix Gogo Command (0.8.0)
3|Active | 1|Apache Felix Gogo Runtime (0.8.0)
4|Active | 1|Apache Felix Gogo Shell (0.8.0)
5|Active | 1|Weld-OSGi :: Core :: Extension Impl (1.0.0.SNAPSHOT)
6|Active | 1|Weld-OSGi :: Implementation :: Weld Integration (1.0.0.SNAPSHOT)
7|Resolved | 1|Weld-OSGi :: Core :: Extension API (1.0.0.SNAPSHOT)
8|Resolved | 1|Weld-OSGi :: Core :: Integration API (1.0.0.SNAPSHOT)
9|Resolved | 1|Weld-OSGi :: Core :: Mandatory (1.0.0.SNAPSHOT)
10|Installed | 1|hello-world (1.0.0)
g!
and start your bean bundle
g! start 10 g! Hello World!
It is greeting the World ! Now stop the bean bundle
stop 10 g! Goodbye World!
and it says goodbye.
Congratulations, you just use CDI in an OSGi environment thank to Weld-OSGi. When you
started your bean bundle Weld-OSGi started to manage it by providing it a Weld
container. Once the container was completely started (and so the HelloWorld
service injection completed) the onStartup
method was called and the bean
bundle application started.
This first bean bundle was very simple, is Weld-OSGi really enabling complex CDI usage
in bean bundle? This section will pick up the hello-world
example again and
improve it by:
Providing three implementations of the HelloWorld
service to
make your bean bundle multilingual (english, french and german)
Force your bean bundle to present itself when is greeting
It will be the hello-world-multilingual
bean bundle.
Every bean bundle gets its own Weld container from the extension bundle, so the CDI usage may stay within the bean bundle boundary:
Any bean in the bean bundle can be injected only in that bean bundle (even exported package classes)
Reciprocally, a bean from another bean bundle cannot be injected in the bean bundle (even imported package classes)
Any decorator, interceptor or alternative declaration in the
beans.xml
file of a bean bundle applies only for
this bean bundle
Furthermore, Weld-OSGi provides Weld container to a bean bundle
when it becomes active in the OSGi environment, so any bundle in another state
is not managed by Weld-OSGi. And an active bean bundle has CDI usage available
only after the Weld container has initialized. In the same way CDI usage is
unavailable once the Weld container has shutdown. That's the reason of
onStartup
and onShutdown
methods from previous section:
A BundleContainerEvents.BundleContainerInitialized
event is fired when CDI usage gets available for the bean
bundle
A BundleContainerEvents.BundleContainerShutdown
event
is fired when CDI usage gets unavailable for the bean bundle
These two events are CDI events and may be observed with regular CDI mechanisms.
public void onStartup(@Observes BundleContainerEvents.BundleContainerInitialized event) { //CDI usage are available in the bean bundle } public void onShutdown(@Observes BundleContainerEvents.BundleContainerShutdown event) { //CDI usage are unavailable in the bean bundle }
Trying
to use CDI mechanisms before the
BundleContainerEvents.BundleContainerInitialized
or after the
BundleContainerEvents.BundleContainerShutdown
event may result
in errors.
First you need to upgrade your HelloWorld
service and make it multilingual:
The com.sample.api.HelloWorld.java
interface
package com.sample.api; public interface HelloWorld { void sayHello(); void sayGoodbye(); }
Nothing has changed here.
The com.sample.api.Language.java
qualifier
annotation
package com.sample.api; import javax.inject.Qualifier; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; @Qualifier (1) @Target({ TYPE, METHOD, PARAMETER, FIELD }) @Retention(RetentionPolicy.RUNTIME) public @interface Language { String value() default "ENGLISH"; (2) }
You create a regular CDI qualifier (1) in order to choose the language of your bean bundle. The language will be choose by providing a string (ENGLISH, FRENCH or GERMAN) to the qualifier (2).
The com.sample.impl.HelloWorldImpl*.java
implementation
classes
package com.sample.impl; import com.sample.api.HelloWorld; import com.sample.api.Language; @Language("ENGLISH") (1) public class HelloWorldEnglish implements HelloWorld { @Override public void sayHello() { System.out.println("Hello World!"); (2) } @Override public void sayGoodbye() { System.out.println("Goodbye World!"); (3) } }
package com.sample.impl; import com.sample.api.HelloWorld; import com.sample.api.Language; @Language("FRENCH") (1) public class HelloWorldFrench implements HelloWorld { @Override public void sayHello() { System.out.println("Bonjour le Monde !"); (2) } @Override public void sayGoodbye() { System.out.println("Au revoir le Monde !"); (3) } }
package com.sample.impl; import com.sample.api.HelloWorld; import com.sample.api.Language; @Language("GERMAN") (1) public class HelloWorldGerman implements HelloWorld { @Override public void sayHello() { System.out.println("Hallo Welt!"); (2) } @Override public void sayGoodbye() { System.out.println("Auf Wiedersehen Welt!"); (3) } }
Here
you just give the language of the implementation using the
Language
qualifier (1),
then you translate the outputs (2)
(3).
Now you will use CDI interceptor to force the bean bundle to present itself every time he greets the World:
The com.sample.api.Presentation.java
interceptor
binding
package com.sample.api;
import javax.interceptor.InterceptorBinding;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
@InterceptorBinding (1)
@Target({ TYPE, METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Presentation {
}
You create a regular CDI interceptor binding (1) in order to add a bean bundle presentation everytime it greets the World.
The com.sample.impl.HelloWorldImpl*.java
implementation
classes
...
public class HelloWorld* implements HelloWorld {
@Override @Presentation (1)
public void sayHello() {
System.out.println("Hello World!");
}
...
}
You
add the interceptor binding on the sayHello
method to force
presentation only when the bean bundle is greeting and not saying
goodbye.
The com.sample.impl.PresentationInterceptor.java
interceptor
package com.sample.impl; import com.sample.api.Presentation; import javax.interceptor.AroundInvoke; import javax.interceptor.Interceptor; import javax.interceptor.InvocationContext; @Interceptor (1) @Presentation public class PresentationInterceptor { @AroundInvoke public Object present(InvocationContext ctx) throws Exception { ctx.proceed(); (2) Language language = ctx.getMethod().getDeclaringClass().getAnnotation(Language.class); (3) if(language != null) { String lang = language.value(); if(lang != null) { if(lang.equals("FRENCH")) { System.out.println("Je suis le bundle hello-world-multilingual"); (4) return null; } else if(lang.equals("GERMAN")) { System.out.println("Ich bin das bundle hello-world-multilingual"); (5) return null; } } } System.out.println("I am the bundle hello-world-multilingual"); (6) return null; } }
The interceptor is declared so by its annotations (1). It prints the normal sentence using the intercepted method (2), then it detects the current language (3) and prints the corresponding description (4) (5) (6).
Now the HelloWorld
service is a bit more complex and you use
several CDI features.
Next you need to update the com.sample.App.java
main
class
package com.sample; import com.sample.api.HelloWorld; import com.sample.api.Language; import org.osgi.cdi.api.extension.events.BundleContainerEvents; import javax.enterprise.event.Observes; import javax.inject.Inject; public class App { @Inject @Language("ENGLISH") (1) HelloWorld helloWorldEnglish; @Inject @Language("FRENCH") (2) HelloWorld helloWorldFrench; @Inject @Language("GERMAN") (3) HelloWorld helloWorldGerman; public void onStartup(@Observes BundleContainerEvents.BundleContainerInitialized event) { (4) helloWorldEnglish.sayHello(); helloWorldFrench.sayHello(); helloWorldGerman.sayHello(); } public void onShutdown(@Observes BundleContainerEvents.BundleContainerShutdown event) { (5) helloWorldEnglish.sayGoodbye(); helloWorldFrench.sayGoodbye(); helloWorldGerman.sayGoodbye(); } }
You
replace the initial HelloWorld
service injection by three qualified
injection, one for each language (1)
(2)
(3). You also update onStartup
and
onShutdown
methods to greet and say goodbye in the three languages
(4)
(5).
Finally you should write the configuration files of your bean bundle:
The pom.xml
Maven configuration
file
<?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sample</groupId> <artifactId>hello-world-multilingual</artifactId> <version>1.0</version> <packaging>bundle</packaging> <dependencies> <dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> </dependency> <dependency> <groupId>javax.enterprise</groupId> <artifactId>cdi-api</artifactId> <version>1.0-SP4</version> </dependency> <dependency> <groupId>org.osgi.cdi</groupId> <artifactId>weld-osgi-core-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <instructions> <_include>-target/classes/META-INF/${project.artifactId}.bnd</_include> </instructions> </configuration> </plugin> </plugins> </build> </project>
Nothing
has changed here, but the artifactId
.
The META-INF\beans.xml
CDI marker
file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors> (1)
<class>com.sample.impl.PresentationInterceptor</class>
</interceptors>
</beans>
You declare your interceptor in order to activate it (1).
The META-INF\hello-world-multilingual.bnd
OSGi configuration
file
# Let bnd handle the MANIFEST.MF generation
Nothing has changed here.
Every time you change the artifactId
of one of your
bean bundle you may also update the name of its bnd file.
artifactId
and bnd file name should be the same in
order to generate a bundle.
Your project should now looks like that:
hello-world-multilingual pom.xml - src - main - java - com.sample App.java - api HelloWorld.java Language.java Presentation.java - impl HelloWorldEnglish.java HelloWorldFrench.java HelloWorldGerman.java PresentationInterceptor.java - resources - META-INF beans.xml hello-world-multilingual.bnd
It is time to try out these CDI features in an OSGi environment:
Build your project using Maven: mvn clean install
Copy the generated hello-world-multilingual-1.0.jar
file to
the Felix home bundle
directory and the remove the old
hello-world-1.0.jar
file.
Update the Felix configuration file to auto install the bean bundle
felix.auto.install.1= file:bundle/weld-osgi-core-api-1.0-SNAPSHOT.jar \
file:bundle/weld-osgi-core-spi-1.0-SNAPSHOT.jar \
file:bundle/weld-osgi-core-mandatory-1.0-SNAPSHOT.jar \
file:bundle/hello-world-multilingual-1.0.jar
Start the Felix framework
____________________________
Welcome to Apache Felix Gogo
g! lb
START LEVEL 1
ID|State |Level|Name
0|Active | 0|System Bundle (3.2.2)
1|Active | 1|Apache Felix Bundle Repository (1.6.2)
2|Active | 1|Apache Felix Gogo Command (0.8.0)
3|Active | 1|Apache Felix Gogo Runtime (0.8.0)
4|Active | 1|Apache Felix Gogo Shell (0.8.0)
5|Active | 1|Weld-OSGi :: Core :: Extension Impl (1.0.0.SNAPSHOT)
6|Active | 1|Weld-OSGi :: Implementation :: Weld Integration (1.0.0.SNAPSHOT)
7|Resolved | 1|Weld-OSGi :: Core :: Extension API (1.0.0.SNAPSHOT)
8|Resolved | 1|Weld-OSGi :: Core :: Integration API (1.0.0.SNAPSHOT)
9|Resolved | 1|Weld-OSGi :: Core :: Mandatory (1.0.0.SNAPSHOT)
10|Installed | 1|hello-world-multilingual (1.0.0)
g!
and start your bean bundle
g! start 10 g! Hello World! I am the bundle hello-world-multilingual Bonjour le Monde ! Je suis le bundle hello-world-multilingual Hallo Welt! Ich bin das bundle hello-world-multilingual
It is greeting the World in the three languages (and in the right order)! And it is also presenting itself. Now stop the bean bundle
stop 10 g! Goodbye World! Au revoir le Monde ! Auf Wiedersehen Welt!
and it also says goodbye in the three languages.
CDI seems to respond perfectly in an OSGi environment, thank to Weld-OSGi. But it is sad to use only one bundle for your application, in the next chapter we will see how Weld-OSGi allow to use OSGi powerfulness coupled with CDI easiness in multi bundles application.