JBoss ShrinkWrap. Adding a file from another module.

A project with several modules.

enter image description here

In my ejb module I have dedicated files. I would like to use the same files that run the arquillian test in the web module.

In the pom.xml file in the web module, I have a dependency on the ejb module, but with scope, since I don't want to get the "real" persistence.xml from the 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 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 for this. ?? Thanks

+5
source share
1 answer

A quick and dirty way would be to check if these files can be found in the classpath by checking ejb / target / classes. If so, just add:

 .addAsResource(g4TravelCenterTest-ds.xml) .addAsResource(import.sql) .addAsResource(META-INF/test-persistence.xml) 
0
source

Source: https://habr.com/ru/post/1236181/


All Articles