Maven now successfully builds the PAR for your application, however the dependencies 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 dependancies. This is required to ensure the Web bundle has the correct set of dependancies as well as the other bundles. Normally they would simply be resolved transitively from the bundle projects but the ‘war’ project does not pass on its dependancies; it expects them to be contained in its ‘lib’ directory. For this reason its dependancies must be given explicitly.
<!-- Required for the web bundle as dependancies 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 dependancies in a lib directory as they will be provided
by the runtime enviroment. Add the following build section to the greenpages.web
POM file.
<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/chrisfrost/Repos/GIT/greenpages/solution/ greenpages/target/greenpages-solution-2.0.0.SNAPSHOT.par' [INFO] Added 'greenpages.app-solution.jar' [INFO] Added 'greenpages.jpa-solution.jar' [INFO] Added 'greenpages.db-solution.jar' [INFO] Added 'greenpages.web-solution.war'
If the dependencies are produced, proceed to the next step.