Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JBoss ShrinkWrap. Adding file from other module.

Multi module project.

enter image description here

In my ejb module I have the highlighted files. I would like to use the same files running a arquillian test in the web module.

In the pom.xml file in web module I have a dependency to the ejb module, but with scope provided as I do not want the get the "real" persistence.xml from ejb module.

<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>

So in the RestTest class I want to include the files from the ejb module..

@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;
}

What is the best approach to do that. ?? Thanks

like image 350
klind Avatar asked Nov 17 '15 19:11

klind


1 Answers

A quick and dirty way would be to check if these files can be found on the classpath, by checking ejb/target/classes. If this is the case, simply add:

.addAsResource(g4TravelCenterTest-ds.xml)
.addAsResource(import.sql)
.addAsResource(META-INF/test-persistence.xml)
like image 131
georg-un Avatar answered Oct 25 '22 07:10

georg-un