Search code examples
jakarta-eedeploymentejb-3.0dependency-managementglassfish-2.x

EJB modules cannot find class from another EJB module on glassfish


I have an EJB 3 module deployed on my Glassfish 2.1 server.

I'm trying to deploy a second EJB module, which depends on this first module, but the deployment fails with java.lang.NoClassDefFoundError about a class that can be found in the first EJB Module.

What's the best way to solve this dependecy between 2 EJB modules? I want to deploy them separately, and not have them in the same EAR.

More specifically, I have a Dependecy Injection of an EJB from my first EJB Module in one of my EJBs of my second EJB module:

@EJB (name="ejb/FirstEJB")
private FirstEJBRemote ejb;

But during deployment I get NoClassDefFoundError about the class FirstEJBRemote:

Error in annotation processing: java.lang.NoClassDefFoundError: FirstEJBRemote

Solution

  • Miljen Mikic has a point about the whole Classloaders loading commonly named classes if they wouldn't be isolated.

    But with Glassfish, what you should do in your case is place your First EJB module in the directory glassfish_home/domains/domain1/lib/applibs. Then during deployment of the Second EJB module you can specify that the First EJB module's jar should be loaded for this EJB module that is being deployed.

    That's called Application-specific class loading, and here's more about it: http://docs.oracle.com/cd/E19798-01/821-1752/gatej/index.html