1

When I created my first empty Entreprise Application with Maven, I had this error, even when I created an Entity:

    Invalid ejb 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.

Entity.java:

package test;

import java.io.Serializable;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;


@javax.persistence.Entity
public class Entity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
}

Then I found that the solution to this issue is to add @Stateless to the `Entity Class: package test;

import java.io.Serializable;
import javax.ejb.Stateless;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Stateless
@javax.persistence.Entity
public class Entity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
}

It works fine, but now I want to know why I had to add this annotation to the Entity to work fine ?

The config details are:

  • Netbeans 8.1
  • Glassfish 4.1.1
  • pgAdmin III
  • Maven 3.5

The EAR module has the maven-ear-plugin configured as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <version>6</version>
        <defaultLibBundleDir>lib</defaultLibBundleDir>
    </configuration>
</plugin>
Mehdi Bouzidi
  • 1,937
  • 3
  • 15
  • 31

1 Answers1

1

It's possible that the presence of that @Stateless annotation will cause weird stuff to happen at runtime, so you should remove that.

As your resulting jar contains zero EJBs then it's packaging type should be changed from ejb to jar.

Make sure that your maven-ear-plugin looks something like:

        <plugin>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.10.1</version>
            <configuration>
                <version>7</version>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <modules>
                    <!-- no ejb module -->
                    <webModule>
                       ...
                    </webModule>
                </modules>
            </configuration>
        </plugin>

and your application should deploy properly.

Furthermore, as you're using GlassFish 4.x, you could dispense with the "Enterprise Application" altogether and just put everything in your WAR file which can then be deployed on it's own.

You can even add EJBs to the WAR later if you want.

These days you would only use an EAR when you're working on an ancient monolith. Make your build only as complicated as needed.

Steve C
  • 18,876
  • 5
  • 34
  • 37