简体   繁体   中英

How to use the class in an OSGI bundle jar file directly?

In our system, some classes are packaged as OSGI bundle jar file. These jar files will be used in the Glassfish server which support OSGI.

I want to write a test client code to call some methods in these bundle jar files. But I don't want to use Glassfish. I only want to use Tomcat or Jetty.

We are using Maven to management the dependency. The bundle pom is like:

<artifactId>oursystem-name-biz</artifactId>
<packaging>bundle</packaging>
<name>oursystem-name-biz</name>

Is it possible to use these bundled jar files with OSGI supporting?

It depends.

Yes, you can just put a bundle on the standard Java classpath and load classes from it, but only if those classes are in the root of the jar.

However, OSGi supports the notion of a Bundle-Classpath and that (like the Java classpath) is a path that will be searched within the bundle. That means you can create a list of locations to search, like specific subdirectories in the jar or, jars embedded in the jar. Neither of these are supported if you stick the jar on the Java classpath, so if that is your goal, make sure to avoid Bundle-Classpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM