Search code examples
web-applicationsnetbeansjakarta-eeejb-3.0glassfish-3

Splitting EJBs and interfaces into separate module -- deployment fails


I'm having trouble following this guide to "extract" my interfaces and entities from my EAR to use them from another Web Application:

  • I use NetBeans 6.8 and Glassfish 3.0.1
  • "Java Class Library" project
    • contains all the entities and interfaces
  • "Java EE Application" project
    • class library added to the project, is packaged into the EAR
    • contains EJB implementations, MDBs, Test
  • "Java Web Application" project
    • class library added to the project, is packaged into the WAR
    • contains REST interface

When I build and deploy the Web Application, all goes well.

When I build the Java EE application, I can see the jar-file (interfaces, entities) being included. But when I try to deploy the EAR, Glassfish refuses it with a java.lang.NoClassDefFoundError error:

[#|2010-03-28T18:25:59.875+0200|WARNING|glassfishv3.0|javax.enterprise.system.tools.deployment.org.glassfish.deployment.common|_ThreadID=28;_ThreadName=Thread-1;|Error in annotation processing: java.lang.NoClassDefFoundError: mvs/core/StoreServiceLocal|#]

[#|2010-03-28T18:25:59.876+0200|SEVERE|glassfishv3.0|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=28;_ThreadName=Thread-1;|Exception while deploying the app
java.lang.IllegalArgumentException: Invalid ejb jar [CoreServer]: it contains zero ejb. 
Note: 
1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message-driven bean. 
2. EJB3+ entity beans (@Entity) are POJOs and please package them as library jar. 
3. If the jar file contains valid EJBs which are annotated with EJB component level annotations (@Stateless, @Stateful, @MessageDriven, @Singleton), please check server.log to see whether the annotations were processed properly.

'mvs/core/StoreServiceLocal' is an interface which is defined in the library jar file.

What am I doing wrong?

I'm using EJB3 Annotations, so there is no bean-specific deployment descriptor:

mvs/core/ShopperService.java:

@Stateless
public class ShopperService implements ShopperServiceLocal, ShopperServiceRemote {
}

mvs/core/ShopperServiceLocal.java:

@Local
public interface ShopperServiceLocal {
}

Solution

  • Your "Java EE Application" project must contain the interfaces (that currently can't be loaded at runtime, hence the NoClassDefFoundError). And If you want to call the EJBs from another webapp, create an additional "client" jar (with the interfaces only).