Running a jar included in an OSGi bundle

The situation is that I need to package a runnable jar, X.jar into an OSGi bundle. The jar itself can not be modified and OSGi is mandatory as X.jar is to be distributed and run via a software program that requires OSGi bundles. The application contained in X.jar is to communicate over a network with another application.

My plan was to create an OSGi bundle with eclipse and then include X.jar in it. But the problem is that X.jar is not detected. If I instead try to access a copy of X.jar on my file system it works. My bundle file structure:

 -MyBundle
   -META-INF
     -MANIFEST.MF
   -src
     -mybundle
       -Activator.class
   -X.jar

Activator:

 public void start(BundleContext context)  {
    Thread XThread = new Thread(){
        public void run(){
            try {
                 Runtime.getRuntime().exec("java -jar X.jar");
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                       e.printStackTrace();
            }
        }
      };
 }

Manifest.MF

 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Bundle
 Bundle-SymbolicName: myBundle
 Bundle-Version: 1.0.0.qualifier
 Bundle-Activator: com.ericsson.mas.Activator
 Bundle-ClassPath: .,X.jar
 Bundle-Vendor: BundleVendor
 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Import-Package: org.osgi.framework;version="1.3.0"

I suspect that there is some problem with my Bundle-ClassPath, but it seems correct when I search around. Any help is greatly appreciated.

Note: I am aware that this goes completely against OSGi's philosophy.


If you want to run it as an external java process, you will need to extract the jar from your bundle and point to the extracted jar. Your bundle data file storage is a good place to extract the bundle. Putting the jar on the class path only helps if you want to load the classes directly in your activator.

链接地址: http://www.djcxy.com/p/74728.html

上一篇: 设置OSGI包的startlevel

下一篇: 运行一个包含在OSGi包中的jar