This entry discusses the approach to provide the required jar files in the classpath of a Java client in order to access EJBs remotely. I will exemplify this approach for two JEE application servers, JBoss and GlassFish.
I have been using JBoss Application server for a while in my projects. One nice thing about JBossis that it provides a client folder containing a set of jars that you have to add to the classpath of remote applications in order to call EJB remotely. In this way, you have a clear view of what jars you are using.
On the other hand, for Glassfish you need to add one jar (gf-client.jar) in the classpath of the remote application. The drawback is that this jar has a lot of relative dependencies in the MANFEST.MF so it was hard to clearly identify only the files that are needed for a rich client for instance.
Well, this “manual” approach was used before Maven. Things changed with the rise and the efficiency of Maven. To set the classpath of your remote client, you should add the right dependencies in the pom.xml.
JBOSS community edition provides a maven dependency starting from version 5.1.0.
org.jboss.jbossas jboss-as-client pom 5.1.0.GA
Using this dependency, I was expecting that this will download the same jars as in the client folder… except that there are a lot more…
To perform a remote call to en EJB deployed in a GlassFish application server, you need to add next dependency in your pom:
org.glassfish.appclient gf-client-module 3.1
Moreover, if you want to isolate these jars (in order to use them if you can’t benefit from Maven – OSGi bundle for instance, or simply internet connection not available) use maven copy-dependencies to copy in a given folder and add them to your classpath:
The line <excludeTransitive>false</excludeTransitive> is important here as you need to have all dependencies not only first level one.org.apache.maven.plugins maven-dependency-plugin copy-dependencies install copy-dependencies false ${basedir}/lib true
PS: Obviously, in order to be able to access remotely the EJB:
- You must use Remote interfaces
- If you have configured a secure realm, you will need to set up a JAAS security login to the EJB tier
- Configure properly the jndi properties
No comments:
Post a Comment