Maven now successfully builds the PAR for your application. However, the dependecies of the PAR
are not apparent. In this step the Maven dependency
plugin is added to
collect the transitive dependency graph for the PAR.
In the <build><plugins>…</plugins></build>
section (after the par
plugin
declaration), add a plugin declaration for the dependency
plugin.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/par-provided</outputDirectory> <overWriteIfNewer>true</overWriteIfNewer> <excludeGroupIds>com.springsource.dmserver,org.apache.log4j</excludeGroupIds> </configuration> </execution> </executions> </plugin>
A dependency on Freemarker needs to be added to the other dependencies. This is required to ensure the Web bundle has the correct set of dependencies as well as the other bundles. Normally they would be resolved transitively from the bundle projects but the ‘war’ project does not pass on its dependencies, it expects them to be contained in its ‘lib’ directory. For this reason its dependencies must be given explicitly.
<!-- Required for the web bundle as dependencies are not propagated up from war build types --> <dependency> <groupId>org.freemarker</groupId> <artifactId>com.springsource.freemarker</artifactId> <scope>provided</scope> </dependency>
The next step is to stop the Web bundle including its dependencies in a lib directory as they will be provided
by the runtime enviroment. The following build section in the greenpages.web
POM file achieves this:
<build> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1-beta-1</version> <configuration> <packagingExcludes>WEB-INF/lib/**</packagingExcludes> </configuration> </plugin> </plugins> </build>
Run the following command.
mvn clean package
When the command has completed, it will have copied all of the PAR’s dependencies into the
target/par-provided
directory.
The output from Maven should include lines like these
[INFO] [par:par] [INFO] Assembling Artifacts for PAR '/Users/spowell/myopt/Greenpages/greenpages-2.0.0.RELEASE/start/greenpages/target/greenpages-2.0.0.SNAPSHOT.par' [INFO] Added 'greenpages.app.jar' [INFO] Added 'greenpages.jpa.jar' [INFO] Added 'greenpages.db.jar' [INFO] Added 'greenpages.web.war'
If the dependencies are produced, proceed to the next step.