9
我想使用Maven構建和部署遠程EJB。後來,我希望能夠將這個EJB注入並使用到一個單獨的WAR項目中。如何使用Maven構建和部署遠程EJB?
所以我想我需要一個定義接口的jar文件,並在兩個項目(ejb和war)中使用jar。
我有這樣的接口,在Maven項目叫example:api
,打包成JAR:
package example;
import javax.ejb.Remote;
@Remote
public interface Bean {
void process();
}
我實現另一個叫example:ejb
Maven項目上面的接口,封裝成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,如果它有任何區別。
你知道我在做什麼錯嗎?