JBoss ShrinkWrap.从其他模块添加文件.

kli*_*ind 11 jboss dependencies shrinkwrap

多模块项目.

在此输入图像描述

在我的ejb模块中,我有突出显示的文件.我想在Web模块中使用运行arquillian测试的相同文件.

在web模块的pom.xml文件中,我依赖于ejb模块,但提供了范围,因为我不希望从ejb模块获取"真正的"persistence.xml.

<dependency>
        <groupId>com.comp</groupId>
        <artifactId>g4tc-ejb</artifactId>
        <type>ejb</type>
        <!-- Use scope provided as we are creating an ear file, and we do not want the packaged jar file in test, as we want the test-persistence.xml -->
        <scope>provided</scope>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

所以在RestTest类中我想要包含ejb模块中的文件.

@Deployment
public static WebArchive getDeployment() {

    File[] files = Maven.resolver().loadPomFromFile("pom.xml")
            .importRuntimeAndTestDependencies().resolve().withTransitivity().asFile();

    WebArchive war = ShrinkWrap.create(WebArchive.class, "g4tcRestWebservice.war")
            .addAsLibraries(files)
            .addPackages(true, "com.comp.g4tc.web")
            .addPackages(true, "com.comp.g4tc.ejb") /* Load the classes from the ejb module instead of through dependency to avoid getting
                                                    the g4tc-ejb/src/java/resources/META-INF/persistence.xml, we want the one from the test package */
            .addAsResource( "HERE AT THE test-persistence.xml FROM THE EJB MODULE", "META-INF/persistence.xml");

    System.out.println(war.toString(true));
    return war;
}
Run Code Online (Sandbox Code Playgroud)

这样做的最佳方法是什么??? 谢谢

geo*_*-un 1

一种快速但肮脏的方法是通过检查 ejb/target/classes 来检查是否可以在类路径上找到这些文件。如果是这种情况,只需添加:

.addAsResource(g4TravelCenterTest-ds.xml)
.addAsResource(import.sql)
.addAsResource(META-INF/test-persistence.xml)
Run Code Online (Sandbox Code Playgroud)