Creating an ear file using Shrinkwrap using the pom's of a multi-module maven project
jobame Feb 13, 2013 4:39 AMHi,
from our maven multi-module project we try to generate an ear archive with Shrinkwrap. The structure is as follows (see ear-POM below for an example).
ab23Bear
ab23BearCommon
ab23BearDomain
ab23BearEAR
ab23BearEJB
ab23BearService
ab23BearWeb
There are many examples out there for archive generation but we don't manage to combine them properly. Will we have to create each module separately as jar/war and then combine them into the ear with addAsModule/addAsLibrary? That would result in a quite big and complex method and if some source files / packages are moved then the method has to be modified again. That seems to be rather error-prone.
In quite a few examples MavenDependencyResolver but we couldn't find it documented. Is the API documented for MavenDependencyResolver? The most actual version on the web is ShrinkWrap API 1.0.0-cr-3 API (http://docs.jboss.org/shrinkwrap/1.0.0-cr-3/) which does not include that class. Where is it documented?
It seems the examples follow different approaches and we are unsure on how to apply it to our project structure. Would we have e.g. a src/test/resources/arquillian-dep.xml (as described in e.g. https://community.jboss.org/thread/202264)
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>de.ab23.bear</groupId> <artifactId>ab23Bear</artifactId> <version>1.0-SNAPSHOT</version> </parent> <artifactId>de.as24.billing.testdependencies</artifactId> </project>
and a deployment method like the following?
@Deployment(testable = true) public static EnterpriseArchive createDeployment() { String pom = GreeterTest.class.getResource("/arquillian-deps.xml").getFile(); MavenDependencyResolver resolver = DependencyResolvers.use(MavenDependencyResolver.class).loadEffectivePom("classpath:arquillian-deps.xml").importAllDependencies().resolveAs(EnterpriseArchive.class); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "as24BillingTest.ear"); ear.addAsLibraries(resolver.artifact("de.ab23.bear:ab23Bear:1.0-SNAPSHOT").resolveAsFiles()); System.out.println(ear.toString(true)); return ear; }
This, however, currently does not compile due to "org.jboss.shrinkwrap.resolver.api.ResolverEntryPoint cannot be resolved. It is indirectly referenced from required .class files".
Could anybody please point us into the right direction? Is there a rather conrete and best-practice example around?
<?xml version="1.0"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>de.ab23.bear</groupId> <artifactId>ab23Bear</artifactId> <version>1.0-SNAPSHOT</version> </parent> <artifactId>ab23BearEAR</artifactId> <packaging>ear</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>de.ab23.bear</groupId> <artifactId>ab23BearCommon</artifactId> </dependency> <dependency> <groupId>de.ab23.bear</groupId> <artifactId>ab23BearDomain</artifactId> </dependency> <dependency> <groupId>de.ab23.bear</groupId> <artifactId>ab23BearEJB</artifactId> <type>ejb</type> </dependency> <dependency> <groupId>de.ab23.bear</groupId> <artifactId>ab23BearService</artifactId> </dependency> <dependency> <groupId>de.ab23.bear</groupId> <artifactId>ab23BearWeb</artifactId> <type>war</type> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-ear-plugin</artifactId> <version>2.8</version> <configuration> <defaultLibBundleDir>lib</defaultLibBundleDir> <modules> <jarModule> <groupId>de.ab23.bear</groupId> <artifactId>ab23BearCommon</artifactId> <includeInApplicationXml>false</includeInApplicationXml> <bundleFileName>ab23BearCommon.jar</bundleFileName> </jarModule> <jarModule> <groupId>de.ab23.bear</groupId> <artifactId>ab23BearDomain</artifactId> <includeInApplicationXml>false</includeInApplicationXml> <bundleFileName>ab23BearDomain.jar</bundleFileName> </jarModule> <jarModule> <groupId>de.ab23.bear</groupId> <artifactId>ab23BearService</artifactId> <includeInApplicationXml>false</includeInApplicationXml> <bundleFileName>ab23BearService.jar</bundleFileName> </jarModule> <webModule> <groupId>de.ab23.bear</groupId> <artifactId>ab23BearWeb</artifactId> <bundleFileName>ab23BearWeb.war</bundleFileName> </webModule> <ejbModule> <groupId>de.ab23.bear</groupId> <artifactId>ab23BearEJB</artifactId> <bundleFileName>ab23BearEJB.jar</bundleFileName> </ejbModule> </modules> </configuration> </plugin> <plugin> <groupId>org.jboss.as.plugins</groupId> <artifactId>jboss-as-maven-plugin</artifactId> <configuration> <skip>false</skip> </configuration> </plugin> </plugins> </build> </project>