Wiki source code of OSGi Platform

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

Show last authors
1 {{toc/}}
2
3 # Running a JBoss client within OSGi
4
5 I found two possible solutions for accessing EJBs provided by JBoss from within an OSGi bundle:
6
7 ## Creating a bundle containing the JBoss Client libraries
8
9 The first (and preferred) solution is creating an OSGi bundle that contains the JBoss libraries.
10
11 I got the basic idea for this solution from a [tutorial](http://blog.jmc.bz/2007/05/19/using-jboss-ejb-3-with-eclipse-rcp-part-1) 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.
12
13 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`.
14
15 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:
16
17 ```
18 javax.ejb,
19 javax.ejb.spi,
20 javax.enterprise.deploy.model,
21 javax.enterprise.deploy.model.exceptions,
22 javax.enterprise.deploy.shared,
23 javax.enterprise.deploy.shared.factories,
24 javax.enterprise.deploy.spi,
25 javax.enterprise.deploy.spi.exceptions,
26 javax.enterprise.deploy.spi.factories,
27 javax.enterprise.deploy.spi.status,
28 javax.jms,
29 javax.management.j2ee,
30 javax.management.j2ee.statistics,
31 javax.resource,
32 javax.resource.cci,
33 javax.resource.spi,
34 javax.resource.spi.endpoint,
35 javax.resource.spi.security,
36 javax.resource.spi.work,
37 javax.security.jacc,
38 javax.xml.registry,
39 javax.xml.registry.infomodel,
40 org.jboss.aop,
41 org.jboss.aop.advice,
42 org.jboss.aop.instrument,
43 org.jboss.aop.joinpoint,
44 org.jboss.aop.metadata,
45 org.jboss.aop.proxy,
46 org.jboss.aop.util,
47 org.jboss.aspects.asynch,
48 org.jboss.aspects.remoting,
49 org.jboss.aspects.security,
50 org.jboss.aspects.tx,
51 org.jboss.corba,
52 org.jboss.crypto,
53 org.jboss.crypto.digest,
54 org.jboss.deployment,
55 org.jboss.deployment.cache,
56 org.jboss.deployment.scanner,
57 org.jboss.deployment.spi,
58 org.jboss.deployment.spi.beans,
59 org.jboss.deployment.spi.configurations,
60 org.jboss.deployment.spi.factories,
61 org.jboss.deployment.spi.status,
62 org.jboss.ejb,
63 org.jboss.ejb.plugins.cmp.jdbc,
64 org.jboss.ejb.plugins.keygenerator,
65 org.jboss.ejb3,
66 org.jboss.ejb3.asynchronous,
67 org.jboss.ejb3.interceptor,
68 org.jboss.ejb3.mdb,
69 org.jboss.ejb3.mdb.inflow,
70 org.jboss.ejb3.metamodel,
71 org.jboss.ejb3.naming,
72 org.jboss.ejb3.naming.client.java,
73 org.jboss.ejb3.proxy,
74 org.jboss.ejb3.proxy.handle,
75 org.jboss.ejb3.remoting,
76 org.jboss.ejb3.service,
77 org.jboss.ejb3.session,
78 org.jboss.ejb3.stateful,
79 org.jboss.ejb3.stateless,
80 org.jboss.ejb3.statistics,
81 org.jboss.ha.framework.interfaces,
82 org.jboss.ha.framework.server,
83 org.jboss.ha.framework.test,
84 org.jboss.ha.hasessionstate.interfaces,
85 org.jboss.ha.jndi,
86 org.jboss.iiop,
87 org.jboss.iiop.rmi,
88 org.jboss.iiop.rmi.marshal,
89 org.jboss.iiop.rmi.marshal.strategy,
90 org.jboss.injection,
91 org.jboss.injection.lang.reflect,
92 org.jboss.invocation,
93 org.jboss.invocation.http.interfaces,
94 org.jboss.invocation.jrmp.interfaces,
95 org.jboss.invocation.jrmp.server,
96 org.jboss.invocation.pooled.interfaces,
97 org.jboss.invocation.unified.interfaces,
98 org.jboss.invocation.unified.marshall,
99 org.jboss.jmx.adaptor.rmi,
100 org.jboss.jmx.connector.invoker.client,
101 org.jboss.lang,
102 org.jboss.logging,
103 org.jboss.logging.appender,
104 org.jboss.logging.filter,
105 org.jboss.logging.layout,
106 org.jboss.logging.util,
107 org.jboss.management.mejb,
108 org.jboss.monitor.client,
109 org.jboss.mq,
110 org.jboss.mq.il,
111 org.jboss.mq.il.http,
112 org.jboss.mq.il.jvm,
113 org.jboss.mq.il.oil,
114 org.jboss.mq.il.oil2,
115 org.jboss.mq.il.rmi,
116 org.jboss.mq.il.uil2,
117 org.jboss.mq.il.uil2.msgs,
118 org.jboss.mq.referenceable,
119 org.jboss.mq.selectors,
120 org.jboss.mq.xml,
121 org.jboss.mx.capability,
122 org.jboss.mx.interceptor,
123 org.jboss.mx.loading,
124 org.jboss.mx.metadata,
125 org.jboss.mx.modelmbean,
126 org.jboss.mx.notification,
127 org.jboss.mx.persistence,
128 org.jboss.mx.server,
129 org.jboss.mx.server.registry,
130 org.jboss.mx.service,
131 org.jboss.mx.timer,
132 org.jboss.mx.util,
133 org.jboss.mx.util.propertyeditor,
134 org.jboss.naming,
135 org.jboss.naming.client.java,
136 org.jboss.naming.interceptors,
137 org.jboss.net.protocol,
138 org.jboss.net.protocol.file,
139 org.jboss.net.protocol.http,
140 org.jboss.net.protocol.njar,
141 org.jboss.net.protocol.resource,
142 org.jboss.net.sockets,
143 org.jboss.net.ssl,
144 org.jboss.proxy,
145 org.jboss.proxy.compiler,
146 org.jboss.proxy.ejb,
147 org.jboss.proxy.ejb.handle,
148 org.jboss.remoting,
149 org.jboss.remoting.callback,
150 org.jboss.remoting.detection,
151 org.jboss.remoting.detection.jndi,
152 org.jboss.remoting.detection.multicast,
153 org.jboss.remoting.detection.util,
154 org.jboss.remoting.ident,
155 org.jboss.remoting.invocation,
156 org.jboss.remoting.loading,
157 org.jboss.remoting.marshal,
158 org.jboss.remoting.marshal.compress,
159 org.jboss.remoting.marshal.encryption,
160 org.jboss.remoting.marshal.http,
161 org.jboss.remoting.marshal.rmi,
162 org.jboss.remoting.marshal.serializable,
163 org.jboss.remoting.network,
164 org.jboss.remoting.network.filter,
165 org.jboss.remoting.samples.callback,
166 org.jboss.remoting.samples.callback.acknowledgement,
167 org.jboss.remoting.samples.callback.statistics,
168 org.jboss.remoting.samples.chat.client,
169 org.jboss.remoting.samples.chat.exceptions,
170 org.jboss.remoting.samples.chat.server,
171 org.jboss.remoting.samples.chat.utility,
172 org.jboss.remoting.samples.config.factories,
173 org.jboss.remoting.samples.detection.jndi,
174 org.jboss.remoting.samples.detection.jndi.ssl,
175 org.jboss.remoting.samples.detection.multicast,
176 org.jboss.remoting.samples.http,
177 org.jboss.remoting.samples.multiplex,
178 org.jboss.remoting.samples.multiplex.invoker,
179 org.jboss.remoting.samples.oneway,
180 org.jboss.remoting.samples.serialization,
181 org.jboss.remoting.samples.simple,
182 org.jboss.remoting.samples.stream,
183 org.jboss.remoting.samples.transporter.basic,
184 org.jboss.remoting.samples.transporter.basic.client,
185 org.jboss.remoting.samples.transporter.basic.server,
186 org.jboss.remoting.samples.transporter.clustered.client,
187 org.jboss.remoting.samples.transporter.clustered.server,
188 org.jboss.remoting.samples.transporter.complex,
189 org.jboss.remoting.samples.transporter.complex.client,
190 org.jboss.remoting.samples.transporter.complex.server,
191 org.jboss.remoting.samples.transporter.custom.client,
192 org.jboss.remoting.samples.transporter.custom.server,
193 org.jboss.remoting.samples.transporter.multiple,
194 org.jboss.remoting.samples.transporter.multiple.client,
195 org.jboss.remoting.samples.transporter.multiple.server,
196 org.jboss.remoting.samples.transporter.proxy,
197 org.jboss.remoting.samples.transporter.proxy.client,
198 org.jboss.remoting.samples.transporter.proxy.server,
199 org.jboss.remoting.samples.transporter.serialization,
200 org.jboss.remoting.samples.transporter.serialization.client,
201 org.jboss.remoting.samples.transporter.serialization.server,
202 org.jboss.remoting.samples.transporter.simple,
203 org.jboss.remoting.security,
204 org.jboss.remoting.serialization,
205 org.jboss.remoting.serialization.impl.java,
206 org.jboss.remoting.serialization.impl.jboss,
207 org.jboss.remoting.socketfactory,
208 org.jboss.remoting.stream,
209 org.jboss.remoting.transport,
210 org.jboss.remoting.transport.bisocket,
211 org.jboss.remoting.transport.coyote,
212 org.jboss.remoting.transport.coyote.ssl,
213 org.jboss.remoting.transport.http,
214 org.jboss.remoting.transport.http.ssl,
215 org.jboss.remoting.transport.https,
216 org.jboss.remoting.transport.local,
217 org.jboss.remoting.transport.multiplex,
218 org.jboss.remoting.transport.multiplex.utility,
219 org.jboss.remoting.transport.rmi,
220 org.jboss.remoting.transport.servlet,
221 org.jboss.remoting.transport.servlet.web,
222 org.jboss.remoting.transport.socket,
223 org.jboss.remoting.transport.sslbisocket,
224 org.jboss.remoting.transport.sslmultiplex,
225 org.jboss.remoting.transport.sslrmi,
226 org.jboss.remoting.transport.sslservlet,
227 org.jboss.remoting.transport.sslsocket,
228 org.jboss.remoting.transport.web,
229 org.jboss.remoting.transporter,
230 org.jboss.remoting.util,
231 org.jboss.remoting.util.socket,
232 org.jboss.resource,
233 org.jboss.resource.adapter.jdbc,
234 org.jboss.resource.adapter.jdbc.remote,
235 org.jboss.resource.connectionmanager,
236 org.jboss.security,
237 org.jboss.security.auth.callback,
238 org.jboss.security.auth.login,
239 org.jboss.security.jndi,
240 org.jboss.security.plugins,
241 org.jboss.security.srp,
242 org.jboss.security.srp.jaas,
243 org.jboss.security.ssl,
244 org.jboss.serial,
245 org.jboss.serial.classmetamodel,
246 org.jboss.serial.exception,
247 org.jboss.serial.finalcontainers,
248 org.jboss.serial.io,
249 org.jboss.serial.objectmetamodel,
250 org.jboss.serial.objectmetamodel.safecloning,
251 org.jboss.serial.persister,
252 org.jboss.serial.references,
253 org.jboss.serial.util,
254 org.jboss.system,
255 org.jboss.system.pm,
256 org.jboss.system.server,
257 org.jboss.tm,
258 org.jboss.tm.iiop,
259 org.jboss.tm.iiop.client,
260 org.jboss.tm.integrity,
261 org.jboss.tm.usertx.client,
262 org.jboss.tm.usertx.interfaces,
263 org.jboss.tm.usertx.server,
264 org.jboss.util,
265 org.jboss.util.coerce,
266 org.jboss.util.collection,
267 org.jboss.util.deadlock,
268 org.jboss.util.file,
269 org.jboss.util.id,
270 org.jboss.util.loading,
271 org.jboss.util.naming,
272 org.jboss.util.platform,
273 org.jboss.util.property,
274 org.jboss.util.property.jmx,
275 org.jboss.util.propertyeditor,
276 org.jboss.util.state,
277 org.jboss.util.state.xml,
278 org.jboss.util.stream,
279 org.jboss.util.threadpool,
280 org.jboss.util.timeout,
281 org.jboss.util.xml,
282 org.jnp.interfaces,
283 org.jnp.interfaces.java,
284 org.jnp.interfaces.jnp,
285 org.jnp.server,
286 org.omg.stub.javax.ejb
287 ```
288
289 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.
290
291 After doing this, I could simply get the EJBs using JNDI, e.g. using Spring:
292
293 ```xml
294 <jee:jndi-lookup id="testEJB" jndi-name="testear/TestEJB/remote" resource-ref="true">
295 <jee:environment>
296 java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
297 java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
298 java.naming.provider.url=localhost
299 </jee:environment>
300 </jee:jndi-lookup>
301 ```
302
303 ## Placing JBoss JARs within the application bundle
304
305 The other method, that worked for me, was placing the JBoss JARs inside the application bundle:
306
307 I copied all JARs (except `jaxb-xjc.jar`m 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.
308
309 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>`.
310
311 After performing these steps, getting the EJB using JNDI worked without problems.