我在使用pom.xml依賴項創建JUnit測試時遇到了問題。Arquillian ShrinkWrap
測試正在用的Arquillian
@RunWith(Arquillian.class)
運行在此方法中
@Deployment public static JavaArchive createDeployment() {
首先,我創建了一個JavaArchive與包項目我測試
JavaArchive merge = ShrinkWrap.create(JavaArchive.class). addPackages(true, "migrazioneGeaPersistenzaTampone", "migrazioneGeaPersistenza", "it.**.mistral.importGEA4.task", "migrazioneGeaPersistenzaAccess" ). addClasses(java.sql.Connection.class) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
然後當我啓動測試時,有一些丟失的依賴關係
Unable to resolve any beans for Types: [class it.**.**.be.service.EnvironmentRootService]
存在這種依賴
<dependency> <groupId>it.**.mistral</groupId> <artifactId>mistral-be</artifactId> <version>0.1.0</version> <scope>compile</scope> </dependency>
我已經試過很多不同的東西添加這些依賴關係,最好的似乎是使用拆封解析器(https://github.com/shrinkwrap/resolver/blob/master/README.asciidoc,particullarry本款https://github.com/shrinkwrap/resolver/blob/master/README.asciidoc#resolution-of-artifacts-defined-in-pom-files)
a)
JavaArchive[] archives = Maven.resolver().loadPomFromFile(path_to_pom_file). importDependencies(ScopeType.TEST,ScopeType.COMPILE). resolve().withTransitivity().as(JavaArchive.class);
或
Maven.resolver().loadPomFromFile("/path/to/pom.xml").importRuntimeDependencies() .resolve().withTransitivity().asFile();
的關係在任何一種方式忽略了(我失去了一些東西?)
B)
JavaArchive[] mistral_be = Maven.configureResolver().workOffline(). resolve("it.**.mistral:mistral-be:0.1.0").withTransitivity().as(JavaArchive.class);
for (int i = 0; i < mistral_be.length ; i++) {
merge = merge.merge(mistral_be[i]);
}
用一個簡單的
System.out.println(merge.toString(true));
我可以看到,所有來自依賴關係的文件存在!無論如何,我使用本地存儲庫workoffline() 也許我錯過了一些依賴關係?
但離開與
return merge;
該方法將引發「java.lang.NoClassDefFoundError:COM /谷歌/ protobuf的/ GeneratedMessage ....所致:拋出java.lang.ClassNotFoundException:com.google。 protobuf.GeneratedMessage「錯誤。
,有一次我嘗試添加缺少的依賴條件
// Tryn'g to add protobuf dependencies JavaArchive[] prto_buf = Maven.configureResolver().withMavenCentralRepo(true).resolve("com.google.protobuf:protobuf-java:2.3.0").withTransitivity().as(JavaArchive.class);
for (int i = 0; i < prto_buf.length ; i++) { projectPackages = projectPackages.merge(prto_buf[i]); }
拋出sameException ... 再次,用一個簡單的
System.out.println(merge.toString(true));
我可以看到com.Google.protobuf.GeneratedMessage是禮品
提取相關性:
<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>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<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.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<version>2.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.5.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
任何人都可以幫我解決這個問題嗎?
我嘗試部署到受管理的集裝箱(Jboss 7.1.1),但現在我有新問題。任何方式,我接受的答覆,因爲這是嵌入式容器。現在我將打開另一個線程的新問題:) – Antimo 2014-10-19 17:00:49
新問題:) http://stackoverflow.com/questions/26453160/arquillian-shrinkwrap-maven-dependencies-in-pom – Antimo 2014-10-19 17:16:07