Reputation: 143
I'm new to maven and JavaEE. I need to deploy a bean to glassfish 4. Bean code:
@Remote(IBean.class)
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class BeanImpl implements IBean{
...
}
I've created a maven app in Intellij IDEA with the following structure:
1. lib
ejb-api-3.0.jar
mylib.jar
2. META-INF
MANIFEST.MF
persistance.xml
3. src/main/java
com.mypackage
BeanImpl.java
model
4. src/main/resources
my_sql_patches.sql
5. src/test
empty
6. pom.xml
MANIFEST.MF:
Manifest-Version: 1.0
POM.XML:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>myapp-app-bean</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>ru.mylib</groupId>
<artifactId>mylib</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/ejb-api-3.0.jar</systemPath>
</dependency>
</dependencies>
<properties>
<jdk.version>1.8</jdk.version>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<ejbVersion>3.0</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
I make clean install with maven and jar file is built successfully. But then I deploy it on glassfish, and it says me:
Error occurred during deployment: Exception while deploying the app [myapp-app-bean-1.0-SNAPSHOT] : Invalid ejb jar myapp-app-bean-1.0-SNAPSHOT: it contains zero ejb. A valid ejb jar requires at least one session/entity/message driven bean
What's wrong?
Upvotes: 0
Views: 1126
Reputation: 13857
The problem is that you are packaging as JAR instead of EJB. This might be somehow confusing, because both packaging formats end up in a file named .jar
.
Change your pom.xml
accordingly:
<packaging>ejb</packaging>
Additional note:
If you have to package other libs as dependencies, then an EJB is only part of the right solution.
To do it right, you need an EAR which "wraps" the EJB.
Inside the EAR, you can create a lib
folder for your dependencies.
The EAR structure will look similar to this:
/EAR
/EAR/YourEJB.jar
/EAR/lib
/EAR/lib/some-lib.jar
If you are new to all this, I recommend to use NetBeans because it has good Glassfish integration and has examples for the most common Java EE project structures (EJB, EAR, WAR).
Upvotes: 2