OSGi Platform

Last modified by Sebastian Marsching on 2022/05/27 22:43

Running a JBoss client within OSGi

I found two possible solutions for accessing EJBs provided by JBoss from within an OSGi bundle:

Creating a bundle containing the JBoss Client libraries

The first (and preferred) solution is creating an OSGi bundle that contains the JBoss libraries.

I got the basic idea for this solution from a tutorial about JBoss EJB and Eclipse RCP. However, I had to perform some changes as the Export-Package declaration contained packages which were causing conflicts in my OSGi environment.

In order to create the JBoss bundle, I used Eclipse's "Plug-in from existing JAR archives" project wizard. There I selected the jbossall-client.jar and chose not to "Unzip the JAR archives into the project" and created the new plugin project using the plugin-id org.jboss.client.

Then I edited the META-INF/MANIFEST.MF in order to narrow the list of exported packages. When I did not do this, I got problems because of collisions with the same packages in other bundles. I used the following list of exported packages:

javax.ejb,
javax.ejb.spi,
javax.enterprise.deploy.model,
javax.enterprise.deploy.model.exceptions,
javax.enterprise.deploy.shared,
javax.enterprise.deploy.shared.factories,
javax.enterprise.deploy.spi,
javax.enterprise.deploy.spi.exceptions,
javax.enterprise.deploy.spi.factories,
javax.enterprise.deploy.spi.status,
javax.jms,
javax.management.j2ee,
javax.management.j2ee.statistics,
javax.resource,
javax.resource.cci,
javax.resource.spi,
javax.resource.spi.endpoint,
javax.resource.spi.security,
javax.resource.spi.work,
javax.security.jacc,
javax.xml.registry,
javax.xml.registry.infomodel,
org.jboss.aop,
org.jboss.aop.advice,
org.jboss.aop.instrument,
org.jboss.aop.joinpoint,
org.jboss.aop.metadata,
org.jboss.aop.proxy,
org.jboss.aop.util,
org.jboss.aspects.asynch,
org.jboss.aspects.remoting,
org.jboss.aspects.security,
org.jboss.aspects.tx,
org.jboss.corba,
org.jboss.crypto,
org.jboss.crypto.digest,
org.jboss.deployment,
org.jboss.deployment.cache,
org.jboss.deployment.scanner,
org.jboss.deployment.spi,
org.jboss.deployment.spi.beans,
org.jboss.deployment.spi.configurations,
org.jboss.deployment.spi.factories,
org.jboss.deployment.spi.status,
org.jboss.ejb,
org.jboss.ejb.plugins.cmp.jdbc,
org.jboss.ejb.plugins.keygenerator,
org.jboss.ejb3,
org.jboss.ejb3.asynchronous,
org.jboss.ejb3.interceptor,
org.jboss.ejb3.mdb,
org.jboss.ejb3.mdb.inflow,
org.jboss.ejb3.metamodel,
org.jboss.ejb3.naming,
org.jboss.ejb3.naming.client.java,
org.jboss.ejb3.proxy,
org.jboss.ejb3.proxy.handle,
org.jboss.ejb3.remoting,
org.jboss.ejb3.service,
org.jboss.ejb3.session,
org.jboss.ejb3.stateful,
org.jboss.ejb3.stateless,
org.jboss.ejb3.statistics,
org.jboss.ha.framework.interfaces,
org.jboss.ha.framework.server,
org.jboss.ha.framework.test,
org.jboss.ha.hasessionstate.interfaces,
org.jboss.ha.jndi,
org.jboss.iiop,
org.jboss.iiop.rmi,
org.jboss.iiop.rmi.marshal,
org.jboss.iiop.rmi.marshal.strategy,
org.jboss.injection,
org.jboss.injection.lang.reflect,
org.jboss.invocation,
org.jboss.invocation.http.interfaces,
org.jboss.invocation.jrmp.interfaces,
org.jboss.invocation.jrmp.server,
org.jboss.invocation.pooled.interfaces,
org.jboss.invocation.unified.interfaces,
org.jboss.invocation.unified.marshall,
org.jboss.jmx.adaptor.rmi,
org.jboss.jmx.connector.invoker.client,
org.jboss.lang,
org.jboss.logging,
org.jboss.logging.appender,
org.jboss.logging.filter,
org.jboss.logging.layout,
org.jboss.logging.util,
org.jboss.management.mejb,
org.jboss.monitor.client,
org.jboss.mq,
org.jboss.mq.il,
org.jboss.mq.il.http,
org.jboss.mq.il.jvm,
org.jboss.mq.il.oil,
org.jboss.mq.il.oil2,
org.jboss.mq.il.rmi,
org.jboss.mq.il.uil2,
org.jboss.mq.il.uil2.msgs,
org.jboss.mq.referenceable,
org.jboss.mq.selectors,
org.jboss.mq.xml,
org.jboss.mx.capability,
org.jboss.mx.interceptor,
org.jboss.mx.loading,
org.jboss.mx.metadata,
org.jboss.mx.modelmbean,
org.jboss.mx.notification,
org.jboss.mx.persistence,
org.jboss.mx.server,
org.jboss.mx.server.registry,
org.jboss.mx.service,
org.jboss.mx.timer,
org.jboss.mx.util,
org.jboss.mx.util.propertyeditor,
org.jboss.naming,
org.jboss.naming.client.java,
org.jboss.naming.interceptors,
org.jboss.net.protocol,
org.jboss.net.protocol.file,
org.jboss.net.protocol.http,
org.jboss.net.protocol.njar,
org.jboss.net.protocol.resource,
org.jboss.net.sockets,
org.jboss.net.ssl,
org.jboss.proxy,
org.jboss.proxy.compiler,
org.jboss.proxy.ejb,
org.jboss.proxy.ejb.handle,
org.jboss.remoting,
org.jboss.remoting.callback,
org.jboss.remoting.detection,
org.jboss.remoting.detection.jndi,
org.jboss.remoting.detection.multicast,
org.jboss.remoting.detection.util,
org.jboss.remoting.ident,
org.jboss.remoting.invocation,
org.jboss.remoting.loading,
org.jboss.remoting.marshal,
org.jboss.remoting.marshal.compress,
org.jboss.remoting.marshal.encryption,
org.jboss.remoting.marshal.http,
org.jboss.remoting.marshal.rmi,
org.jboss.remoting.marshal.serializable,
org.jboss.remoting.network,
org.jboss.remoting.network.filter,
org.jboss.remoting.samples.callback,
org.jboss.remoting.samples.callback.acknowledgement,
org.jboss.remoting.samples.callback.statistics,
org.jboss.remoting.samples.chat.client,
org.jboss.remoting.samples.chat.exceptions,
org.jboss.remoting.samples.chat.server,
org.jboss.remoting.samples.chat.utility,
org.jboss.remoting.samples.config.factories,
org.jboss.remoting.samples.detection.jndi,
org.jboss.remoting.samples.detection.jndi.ssl,
org.jboss.remoting.samples.detection.multicast,
org.jboss.remoting.samples.http,
org.jboss.remoting.samples.multiplex,
org.jboss.remoting.samples.multiplex.invoker,
org.jboss.remoting.samples.oneway,
org.jboss.remoting.samples.serialization,
org.jboss.remoting.samples.simple,
org.jboss.remoting.samples.stream,
org.jboss.remoting.samples.transporter.basic,
org.jboss.remoting.samples.transporter.basic.client,
org.jboss.remoting.samples.transporter.basic.server,
org.jboss.remoting.samples.transporter.clustered.client,
org.jboss.remoting.samples.transporter.clustered.server,
org.jboss.remoting.samples.transporter.complex,
org.jboss.remoting.samples.transporter.complex.client,
org.jboss.remoting.samples.transporter.complex.server,
org.jboss.remoting.samples.transporter.custom.client,
org.jboss.remoting.samples.transporter.custom.server,
org.jboss.remoting.samples.transporter.multiple,
org.jboss.remoting.samples.transporter.multiple.client,
org.jboss.remoting.samples.transporter.multiple.server,
org.jboss.remoting.samples.transporter.proxy,
org.jboss.remoting.samples.transporter.proxy.client,
org.jboss.remoting.samples.transporter.proxy.server,
org.jboss.remoting.samples.transporter.serialization,
org.jboss.remoting.samples.transporter.serialization.client,
org.jboss.remoting.samples.transporter.serialization.server,
org.jboss.remoting.samples.transporter.simple,
org.jboss.remoting.security,
org.jboss.remoting.serialization,
org.jboss.remoting.serialization.impl.java,
org.jboss.remoting.serialization.impl.jboss,
org.jboss.remoting.socketfactory,
org.jboss.remoting.stream,
org.jboss.remoting.transport,
org.jboss.remoting.transport.bisocket,
org.jboss.remoting.transport.coyote,
org.jboss.remoting.transport.coyote.ssl,
org.jboss.remoting.transport.http,
org.jboss.remoting.transport.http.ssl,
org.jboss.remoting.transport.https,
org.jboss.remoting.transport.local,
org.jboss.remoting.transport.multiplex,
org.jboss.remoting.transport.multiplex.utility,
org.jboss.remoting.transport.rmi,
org.jboss.remoting.transport.servlet,
org.jboss.remoting.transport.servlet.web,
org.jboss.remoting.transport.socket,
org.jboss.remoting.transport.sslbisocket,
org.jboss.remoting.transport.sslmultiplex,
org.jboss.remoting.transport.sslrmi,
org.jboss.remoting.transport.sslservlet,
org.jboss.remoting.transport.sslsocket,
org.jboss.remoting.transport.web,
org.jboss.remoting.transporter,
org.jboss.remoting.util,
org.jboss.remoting.util.socket,
org.jboss.resource,
org.jboss.resource.adapter.jdbc,
org.jboss.resource.adapter.jdbc.remote,
org.jboss.resource.connectionmanager,
org.jboss.security,
org.jboss.security.auth.callback,
org.jboss.security.auth.login,
org.jboss.security.jndi,
org.jboss.security.plugins,
org.jboss.security.srp,
org.jboss.security.srp.jaas,
org.jboss.security.ssl,
org.jboss.serial,
org.jboss.serial.classmetamodel,
org.jboss.serial.exception,
org.jboss.serial.finalcontainers,
org.jboss.serial.io,
org.jboss.serial.objectmetamodel,
org.jboss.serial.objectmetamodel.safecloning,
org.jboss.serial.persister,
org.jboss.serial.references,
org.jboss.serial.util,
org.jboss.system,
org.jboss.system.pm,
org.jboss.system.server,
org.jboss.tm,
org.jboss.tm.iiop,
org.jboss.tm.iiop.client,
org.jboss.tm.integrity,
org.jboss.tm.usertx.client,
org.jboss.tm.usertx.interfaces,
org.jboss.tm.usertx.server,
org.jboss.util,
org.jboss.util.coerce,
org.jboss.util.collection,
org.jboss.util.deadlock,
org.jboss.util.file,
org.jboss.util.id,
org.jboss.util.loading,
org.jboss.util.naming,
org.jboss.util.platform,
org.jboss.util.property,
org.jboss.util.property.jmx,
org.jboss.util.propertyeditor,
org.jboss.util.state,
org.jboss.util.state.xml,
org.jboss.util.stream,
org.jboss.util.threadpool,
org.jboss.util.timeout,
org.jboss.util.xml,
org.jnp.interfaces,
org.jnp.interfaces.java,
org.jnp.interfaces.jnp,
org.jnp.server,
org.omg.stub.javax.ejb

The I exported the plugin, creating a bundle JAR. In the application bundle I added a Require-Bundle: org.jboss.client header in order to make the JBoss client library available to the application. I also placed the EJB interfaces in the classpath of the application bundle.

After doing this, I could simply get the EJBs using JNDI, e.g. using Spring:

<jee:jndi-lookup id="testEJB" jndi-name="testear/TestEJB/remote" resource-ref="true">
   <jee:environment>
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      java.naming.provider.url=localhost
   </jee:environment>
 </jee:jndi-lookup>

Placing JBoss JARs within the application bundle

The other method, that worked for me, was placing the JBoss JARs inside the application bundle:

I copied all JARs (except jaxb-xjc.jarm which was broken and therefore caused problems with the BND plugin) from the JBoss client directory into the application bundle. Then I added all the JARs to the Bundle-ClassPath header.

As I was using the Maven BND plugin, I had to ensure, that not all missing packages were imported and not all available packages were imported. Therefore I made sure not to use * in neither <Import-Package> nor <Export-Package>. In fact, I even used !* in <Import-Package>.

After performing these steps, getting the EJB using JNDI worked without problems.