Java Reference
In-Depth Information
Listing 16.4
Manifest file for the calculator bundle
Bundle-Name: Calculator
Bundle-Description: A sample calculator bundle that registers the
calculator service
Bundle-Vendor: Apache Felix
Bundle-Version: 1.0.0
Bundle-Activator: com.manning.junitbook.ch16.CalculatorBundleActivator
Export-Package: com.manning.junitbook.ch16.service
Import-Package: org.osgi.framework
Every OSG i bundle is a JAR file, and what distinguishes the JAR as an OSG i bundle is
the MANIFEST . MF file. In the MANIFEST . MF file, we specify different kinds of metadata
for our bundle. The first few lines provide the name, description, vendor, and version
of the bundle B . The Bundle-Activator C specifies the full name of the Activator
class (the one that implements BundleActivator ). As we already mentioned, a bundle
can export services. Which package is exported is specified in the Export-Package
clause D . A bundle can also use and demand services; we specify which services we
use with the last clause. There we define the packages that are needed by our service
E . You can specify multiple values separated by commas.
The final step is to compile the source code and produce the bundle (the JAR file).
Open a shell, navigate to the ch16-osgi\calculator-service folder, and type in the com-
mand to use Maven
B
C
D
E
mvn clean install
or the command to use Ant
ant
The result should be the same: a JAR file containing the classes and the MANIFEST . MF
file in a META-INF folder.
Now that we have the bundle JAR that contains our service, we use the Felix con-
sole and install the bundle. Navigate to the FELIX_HOME directory and execute the
following command:
java -jar bin/felix.jar
You'll see the following:
Welcome to Felix.
=================
->
The Felix console is up and running, and you can now manage your services. The
first thing you can do from here is list all the services that are installed. Type in
the command
-> ps
For a complete list of all the commands you can use, type in the help command:
-> help
 
 
Search WWH ::




Custom Search