Using JBoss EJB 3 with Eclipse RCP [Part 1]
I got a lot of hits to my article about how to connect an Eclipse Rich Client Project to JBoss and EJB 3. Most of these hits came from people outside of germany and they left right after entering the page. So I think that there is some interest in an english version of this article.
We want to create an Eclipse Rich Client Project (RCP for now on) consisting of the RCP-plugin and a second plugin containing the JBoss client JARs. To keep things simple, the EJB-Classes will be hold directly in the RCP-Plugin. In a later article I will show how to extract the business-classes in an extra plugin to ensure better maintainablity.
The OSGI-Classloader from Eclipse creates an extra Classpath for any plugin it loads. Classes from other plugins are therefore invisible. This behavior is pretty good in generel because it allows Eclipse e.g. to enable or disable plugins at runtime. But sometimes it is necessary to give plugin A access to classes in plugin B. This can be archived by declaring a dependency between A and B.
But for our problem we need access in both directions. Our RCP needs “to see” the JBoss classes and JBoss needs access to our EJBs. And because this is not possible you will get a lot of
Javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: bz.jmc.blog.tutorial.rcp_with_jboss.ejb.MyTestStatelessSessionRemote (no security manager: RMI class loader disabled)]
and other errors.
As mentioned above, you can’t set a dependency in both directions. We need another solution for this particular problem and this solution is called “Buddy Classloading”. So it is possible to “open” one plugin for others. Other Plugins can register as a buddy and give access to their classes.
In some upcoming articles I will create a small tutorial project with screenshots, illustrating the buddy classloading solution.