This content has been marked as final.
Show 2 replies
-
1. Re: Is Arquillian/ShrinkWrap so difficult to use?
plexusnexus Jul 30, 2012 7:13 AM (in response to deadlock_gr)
Hi Markos,you are right, building an EAR with many dependencies is not the easiest thing to do, but possible if you use Maven and follow the following steps:
- Create a separete POM with all the dependencies you want do include in your EAR deployment. Call it test-dependencies.xml and put it below src/test/resources. It should inherit your parent POM to reuse all the managed dependencies.
- Ensure a unique and meaning foll naming schema for your Maven artifact. The artifactId should allow you to determine the type of the artifact (EAR, WAR or simple Jar). All my artifacts containing EJBs have the suffix service.
- Configure your MavenDepencyResolver with the test-dependencies.xml POM like this:
String pom = RegistrationServiceArquillianModuleTest.class.getResource("/test-dependencies.xml").getFile();
EnterpriseArchive earArchive = ShrinkWrap.create(EnterpriseArchive.class, "test.ear");
MavenDependencyResolver resolver = DependencyResolvers.use(MavenDependencyResolver.class)
.includeDependenciesFromPom(pom)
.goOffline();
- Then resolve the artifacts to add as module and as libs separately using MavenResolutionFilter:
Collection ejbArchives = resolver.resolveAs(JavaArchive.class, new MavenResolutionFilter() { private final Pattern COMPILE = Pattern.compile(":"); @Override public boolean accept(MavenDependency mavenDependency) { String[] coords = COMPILE.split(mavenDependency.getCoordinates()); boolean isService = coords[1].endsWith("service"); boolean isOurs = coords[0].startsWith("my.company"); boolean toBeIncluded = isOurs && isService; if (toBeIncluded) { System.out.println("=> " + mavenDependency.getCoordinates()); } return toBeIncluded; } @Override public MavenResolutionFilter configure(Collection mavenDependencies) { return null; } }); Collection libArchives = resolver.resolveAs(JavaArchive.class, new MavenResolutionFilter() { private final Pattern COMPILE = Pattern.compile(":"); @Override public boolean accept(MavenDependency mavenDependency) { String[] coords = COMPILE.split(mavenDependency.getCoordinates()); boolean isService = coords[1].endsWith("service"); boolean isOurs = coords[0].startsWith("my.company"); boolean isLibrary = !(isOurs && (isService)); return isLibrary; } @Override public MavenResolutionFilter configure(Collection mavenDependencies) { return null; } }); JavaArchive jarModule = ShrinkWrap.create(JavaArchive.class, createJarName()) .addPackage(RegistrationService.class.getPackage()) .addClass(RegistrationServiceTestHelperBean.class) .addAsManifestResource("META-INF/persistence.xml", "persistence.xml"); WebArchive warArchive = ShrinkWrap.create(WebArchive.class, createWarName()) .addClass(RegistrationServiceArquillianModuleTest.class); // Now add the tests! earArchive.addAsManifestResource("glassfish-application.xml") .addAsManifestResource("glassfish-ejb-jar.xml") .addAsModules(warArchive) .addAsModule(jarModule) .addAsLibraries(libArchives); for (JavaArchive javaArchive : ejbArchives) { earArchive.addAsModule(javaArchive); } return earArchive;
- That is all.
This is the way it works for me.
Bye,
Oliver
-
2. Re: Is Arquillian/ShrinkWrap so difficult to use?
iapazmino Jul 31, 2012 10:07 PM (in response to deadlock_gr)You might find this guide useful http://arquillian.org/guides/shrinkwrap_introduction