Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid ejb jar: it contains zero ejb.

Tags:

glassfish

ejb

ear

I have 2 modules: ejb and war, and ear module, that contains them. Modules build successfully, but when I try to deploy ear to glassfish, I recieve this error:

glassfish3.1.2|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=17;_ThreadName=Thread-2;|Exception while deploying the app [EarModule] : Invalid ejb jar [BackEnd-1.0-SNAPSHOT.jar]: 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.|#]

I really don't know what to do, I've found a lot of questions like mine, but there was no solution.

like image 721
Mary Ryllo Avatar asked Mar 11 '13 07:03

Mary Ryllo


1 Answers

I know this is very build specific and it uses Netbeans instead of the OP's IDE but because I was lead here and this will likely be useful to some users:

I had the following build: Netbeans Enterprise Application with Maven Glassfish 4.1 Java EE 7

I had tried migrating from a previous non-maven enterprise application and the clone didn't quite work the way I expected, there was some old ejb jars lying around that I deleted.

I had done quite a few things to fix it:

  1. Ensure theres no ejb jars lying around that shouldn't be there. Ensure that you don't have accidently have the ejb module jar included more than once as this can result in the same error too (Manually deploying the ear and deployment through netbeans sometimes gave me different errors).
  2. I used the @Remote interface on my EJB applications. Now you should not be importing your EJB into your War, you should use the annotations correctly as described https://docs.oracle.com/javaee/7/tutorial/ejb-intro004.htm
  3. (This is more of a note) When you update any of your war or ejb, clean and build them before cleaning and building your ear (sounds funny right?).
  4. If you are using interfaces for your session beans then you should put them in a separate jar, make a new project maven > java application. Do the same thing with your persistence entities. Add these as dependencies to both your ejb and war project.
  5. This doesn't relate to me in particular but you should have at least 1 @stateless (or I think @stateful) annotation in a java class inside your ejb module for it to run (for the module to be considered an ejb).

I likely had to do a few more things that I forgot but if you still run into issues comment below and I'll try to update.

like image 167
Omar Abdel Bari Avatar answered Sep 28 '22 17:09

Omar Abdel Bari