13

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.

Mary Ryllo
  • 2,321
  • 7
  • 34
  • 53

5 Answers5

3

I understood, what was wrong. The problem was in run configurations, I'm using Intellij Idea and in run configurations there was build and make before run of my ear module. I removed this and after maven install it deployed successfully.

Mary Ryllo
  • 2,321
  • 7
  • 34
  • 53
2

You have to add an EJB into your WAR or EAR file. Just Create a new Class and annotate it with @Stateless

greenkode
  • 4,001
  • 1
  • 26
  • 29
2

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.

Omar Abdel Bari
  • 934
  • 9
  • 17
0

Just try to build & install your project using Maven , and then , deploy it in glassfish ( do not run your project directly from your IDE )

Yassine Abainou
  • 145
  • 2
  • 13
0

I encountered this problem as well. It occurred when I had imported a new EJB project into my Eclipse workspace. The project didn't have a reference to the Glassfish libraries then, since it was not yet included in the EAR deployment assembly.

Upon saving the Bean file, the IDE automatically imported javax.inject.Singleton instead of javax.ejb.Singleton. This made the code compile without warnings, but throw the same error as in the original post.

ivospijker
  • 702
  • 1
  • 7
  • 22