当我使用Entreprise Application
创建第一个空的Maven
时,即使我创建了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;
}
然后我发现这个问题的解决方案是将@Stateless
添加到`Entity Class:
包装测试;
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;
}
它工作正常,但现在我想知道为什么我必须将此注释添加到Entity
才能正常工作?
配置详细信息为:
EAR模块的maven-ear-plugin配置如下:
<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>
答案 0 :(得分:1)
@Stateless注释的存在可能会导致在运行时发生奇怪的事情,所以你应该删除它。
由于生成的jar包含零EJB,因此其包装类型应从ejb
更改为jar
。
确保您的maven-ear-plugin看起来像:
<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>
并且您的应用程序应该正确部署。
此外,当您使用GlassFish 4.x时,您可以完全省去“企业应用程序”,只需将所有内容放入WAR文件中,然后可以将其部署在自己的文件中。
如果需要,您甚至可以稍后将EJB添加到WAR中。
现在,当你在古老的巨石上工作时,你只会使用EAR。根据需要使您的构建变得复杂。