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