我是 Arquillian 和 Maven 的新手,这周刚开始接触这两者,所以我为这个简单的问题道歉。不用说,我已经投入了一些真正的时间来学习绳索。对于我的最新技巧,我正在尝试设置标准 EJB 会话 Bean。我的大部分知识来自 Arquillian 入门指南:
http://arquillian.org/guides/getting_started/
http://arquillian.org/guides/getting_started_rinse_and_repeat/
http://docs.jboss.org/arquillian/reference/1.0.0.Alpha1/en-US/html_single/ #d0e395
为了得到错误,我在 Eclipse 中右键单击我的模型项目并选择 Run As-> Run On Server。我收到以下错误:
Caused by: java.lang.ClassNotFoundException: org.jboss.shrinkwrap.api.asset.Asset from [Module "deployment.Model.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:196) [jboss-modules.jar:1.2.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:444) [jboss-modules.jar:1.2.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:432) [jboss-modules.jar:1.2.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:399) [jboss-modules.jar:1.2.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:374) [jboss-modules.jar:1.2.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:119) [jboss-modules.jar:1.2.0.Final-redhat-1]
... 29 more
这是完整的服务器日志:
http://www.williverstravels.com/JDev/Forums/StackOverflow/arquillianEJB/log.txt
这是我的测试课
package model.session;
import static org.junit.Assert.*;
import javax.ejb.EJB;
import model.entity.Project;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(Arquillian.class)
public class SessionTest {
@EJB
private MyManagerLocal service;
@Deployment
public static JavaArchive createTestableDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "example.jar")
.addClasses(MyManagerLocal.class, MyManager.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
return jar;
}
@Test
public void assertEqualsProject() {
Project project = (Project)service.getEntityByPrimaryKey(Project.class, 1L);
assertEquals(project.getProjectId().longValue(), 1L);
}
}
这是我的 pom.xml
<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>Model</groupId>
<artifactId>Model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.1.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.1-RC1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>jboss-embedded</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<version>1.1.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>arquillian-jbossas-managed</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<version>7.1.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
我也有一个 arquillian.xml 文件
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<defaultProtocol type="Servlet 3.0"></defaultProtocol>
<container qualifier="arquillian-jbossas-managed" default="true">
<configuration>
<property name="jbossHome">C:\Dev\eap</property>
<property name="allowConnectingToRunningServer">true</property>
</configuration>
</container>
在使用 JBoss AS 7.2 / EAP 6.1 之后,看起来有些 jar 丢失了,但我原以为 Maven pom.xml 会解决这个问题。任何帮助,将不胜感激。我现在有点失落。
** 更新 ** 我尝试了其他一些 pom.xml 配置,例如将所有 arquillian 范围更改为运行时或完全删除标签。仍然得到同样的错误。我还尝试添加以下内容无效:
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>2.1.0-alpha-1</version>
<scope>runtime</scope>
<type>pom</type>
</dependency>
** 更新 **
据我所知,问题在于我的 pom.xml 中的 jar 行。需要库,但它们没有与 jar 一起打包。所以我回到绘图板上来讨论如何让我的测试工作。我应该将它们打包到另一个项目中吗?当我运行它时,这也会给我带来错误,因为我的测试无法“看到”正在测试的 Model.jar。这正在变成一个加重的catch-22。