I am writing a project for acceptance testing and for various reasons this is dependent on another project which is packaged as a WAR. I have managed to unpack the WAR using the maven-dependency-plugin, but I cannot get my project to include the unpacked WEB-INF/lib/*.jar
and WEB-INF/classes/*
to be included on the classpath so the build fails. Is there a way to include these files into the classpath, or is there a better way of depending on a WAR?
Many thanks.
war:war is the default goal invoked during the package phase for projects with a packaging type of war . It builds a WAR file. war:exploded is generally used to speed up testing during the developement phase by creating an exploded webapp in a specified directory.
The Maven WAR plugin is responsible for collecting and compiling all the dependencies, classes, and resources of the web application into a web application archive.
There's another option since maven-war-plugin 2.1-alpha-2. In your WAR project:
<plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <attachClasses>true</attachClasses> </configuration> </plugin>
This creates a classes artifact which you can use in the acceptance tests project with:
<dependency> <groupId>your-group-id</groupId> <artifactId>your-artifact-id</artifactId> <version>your-version</version> <classifier>classes</classifier> </dependency>
Indeed, by design, Maven doesn't resolve transitive dependencies of a war declared as dependency of a project. There is actually an issue about that, MNG-1991, but it won't be solved in Maven 2.x and I'm not sure that I don't know if overlays allow to workaround this issue. My understanding of the suggested solution is to duplicate the dependencies, for example in a project of type pom.
(EDIT: After some more digging, I found something interesting in this thread that I'm quoting below:
I have been helping out with the development of the AppFuse project over the last month where we make heavy use of the war overlay feature in the Maven war plugin. It is a really nifty feature!
To get max power with war overlays I have developed the Warpath plugin that allows projects to use war artifacts as fully fledged dependencies. In brief:
1) The contents of the /WEB-INF/classes directory in the war dependency artifacts can be included in the project's classpath for normal compile, etc tasks.
2) Transitive dependencies from the war dependency artifacts become available for use by other plugins, e.g. compile and ear - so no more having to include all the dependencies when creating skinny wars!The plugin has now been actively used in the AppFuse project for the last few months, and I feel it is at a point where it is both usable and stable. Would the war plugin team be interested in including the warpath functionality inside the war plugin? It would seem to be the most natural place to host it.
So, I don't have any experience with it, but the maven warpath plugin actually looks nice and simple and is available in the central repo. To use it,include the following plugin configuration element in your pom.xml
file:
[...] <build> <plugins> <plugin> <groupId>org.appfuse</groupId> <artifactId>maven-warpath-plugin</artifactId> <version>1.0-SNAPSHOT</version> <extensions>true</extensions> <executions> <execution> <goals> <goal>add-classes</goal> </goals> </execution> </executions> </plugin> </plugins> </build> [...]
And add the war dependencies you want included in the classpath as warpath type dependencies:
[...] <dependencies> <dependency> <groupId>org.appfuse</groupId> <artifactId>appfuse-web</artifactId> <version>2.0</version> <type>war</type> </dependency> <dependency> <groupId>org.appfuse</groupId> <artifactId>appfuse-web</artifactId> <version>2.0</version> <type>warpath</type> </dependency> </dependencies> [...]
Both the war and warpath dependency types are needed: the war type is used by the Maven war plugin to do the war overlay, the warpath type is used by the Warpath plugin to determine the correct list of artifacts for inclusion in the project classpath.
I'd give it a try.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With