我有以下真实的项目结构:
EAR
- lib/commons.jar
- lib/another dependencies
- ejb.jar
我想用 arquillian 测试它,但我总是遇到异常。
这是我构建 EAR 的 java 方法:
@Deployment
public static Archive<?> createTestArchive() {
//create ear
EnterpriseArchive ear = ShrinkWrap
.create(EnterpriseArchive.class, "test-app.ear");
// create ejb-jar
JavaArchive ejb = ShrinkWrap
.create(JavaArchive.class, "test-ejb.jar")
.addPackage("a.b.ejb")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
// resolve ejb dependencies
File[] dependencies = Maven.resolver()
.loadPomFromFile("pom.xml")
.importDependencies(ScopeType.COMPILE, ScopeType.TEST)
.resolve()
.withTransitivity()
.asFile();
ear.addAsModule(ejb);
ear.addAsLibraries(dependencies);
ear.setApplicationXML("glassfish-resources.xml");
LOGGER.debug("content: " + ear.toString(true));
return ear;
}
内容看起来不错,但有些地方不行,因为我得到了这个异常:
ArquillianServletRunner not found.
Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.
JAR 内容:
/a/
/a/b/
/a/b/ejb/
/a/b/ejb/MyEjb.class
...
/META-INF/
/META-INF/beans.xml
EAR 内容
/test-ejb.jar
/lib/
/lib/commons-444750341265461918.jar
/lib/slf4j-api-1.7.21.jar
/lib/slf4j-log4j12-1.7.21.jar
/lib/guava-21.0.jar
...
/lib/arquillian-testenricher-initialcontext-1.1.13.Final.jar
/lib/payara-embedded-all-4.1.1.171.0.1.jar
/lib/postgresql-42.0.0.jar
/META-INF/
/META-INF/application.xml