如何在arquillian服务部署中添加库?

时间:2015-06-19 07:16:21

标签: java junit jboss jboss-arquillian jmockit

我目前正在使用Arquillian用于jboss(远程),我正在努力让Jmockit工作。我部署了一个工作正常的耳朵,但我收到arquillian-service的错误:

java.lang.NoClassDefFoundError: mockit/internal/state/TestRun

Caused by: java.lang.ClassNotFoundException: mockit.internal.state.TestRun from 
[Module "deployment.arquillian-service:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)

我正在使用jMockit 1.7并在EAR部署中使用它。

如何在此部署中添加库(arquillian-service)

PS:这个部署由arquillian管理,我与它无关。

1 个答案:

答案 0 :(得分:1)

我解决了第三方库的问题如下 - 依赖项列表:

protected static final String[] DEPENDENCIES = {
        ...,
        "xbean:xbean:2.4.0",
        ...
};

将所有它们打包到单独的jar中的方法:

protected JavaArchive thirdPartyLibs() {
    JavaArchive lib = ShrinkWrap.create(JavaArchive.class, "libs.jar");
    for (String dependency : DEPENDENCIES) {
        lib.merge(Maven.resolver().resolve(dependency).withoutTransitivity().asSingle(JavaArchive.class));
    }
    return lib;
}

最终我在打包核心jar时合并它:

protected JavaArchive createJar() {
    return ShrinkWrap.create(JavaArchive.class, "test.jar")
            .addAsManifestResource("META-INF/test-persistence.xml", ArchivePaths.create("persistence.xml"))
            .addAsManifestResource("META-INF/test-beans.xml", ArchivePaths.create("beans.xml"))
            .....
            .merge(thirdPartyLibs());
}

还必须指出使用下一个依赖项:

    <dependency>
        <groupId>org.jboss.shrinkwrap.resolver</groupId>
        <artifactId>shrinkwrap-resolver-bom</artifactId>
        <version>2.1.1</version>
        <scope>test</scope>
        <type>pom</type>
    </dependency>

    <dependency>
        <groupId>org.jboss.shrinkwrap.resolver</groupId>
        <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.shrinkwrap.resolver</groupId>
        <artifactId>shrinkwrap-resolver-impl-maven-archive</artifactId>
        <scope>test</scope>
    </dependency>