我想使用 Maven 构建和部署远程 EJB。稍后,我希望能够将这个 EJB 注入并使用到一个单独的 WAR 项目中。
所以我想我需要一个定义接口的 jar 文件,并在两个项目(ejb 和 war)中使用 jar。
我有这个接口,在一个名为 的 Maven 项目中example:api
,打包为 jar:
package example;
import javax.ejb.Remote;
@Remote
public interface Bean {
void process();
}
我在另一个名为 的 Maven 项目中实现了上述接口example:ejb
,打包为 ejb:
package example;
import javax.ejb.Stateless;
@Stateless
public class Ejb implements Bean {
@Override
public void process() {
}
}
ejb 项目使用maven-ejb-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
这两个项目都依赖于javaee-api
:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
现在把它们放在一起,我制作了第三个 Maven 项目,名为example:ear
,打包为ear
:
<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>example</groupId>
<artifactId>ear</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>ear</packaging>
<name>ear</name>
<dependencies>
<dependency>
<groupId>example</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>example</groupId>
<artifactId>ejb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>ejb</type>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<modules>
<ejbModule>
<groupId>example</groupId>
<artifactId>ejb</artifactId>
</ejbModule>
<jarModule>
<groupId>example</groupId>
<artifactId>api</artifactId>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
问题是我无法部署这个耳朵项目。我收到以下错误:
09:39:39,702 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) JBAS015003: Found ear.ear in deployment directory. To trigger deployment create a file called ear.ear.dodeploy
09:39:39,713 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: Starting deployment of "ear.ear"
09:39:39,773 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "ejb-0.0.1-SNAPSHOT.jar"
09:39:39,793 WARN [org.jboss.modules] (MSC service thread 1-8) Failed to define class example.Ejb in Module "deployment.ear.ear.ejb-0.0.1-SNAPSHOT.jar:main" from Service Module Loader: java.lang.LinkageError: Failed to link example/Ejb (Module "deployment.ear.ear.ejb-0.0.1-SNAPSHOT.jar:main" from Service Module Loader)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:396)
[...]
Caused by: java.lang.NoClassDefFoundError: example/Bean
at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_03]
[...]
Caused by: java.lang.ClassNotFoundException: example.Bean from [Module "deployment.ear.ear.ejb-0.0.1-SNAPSHOT.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
我正在使用 JBoss AS 7.1.1,如果它有什么不同的话。
你知道我做错了什么吗?