This is probably an abuse of the tomcat maven plugin, but here is the solution I found. By the way, your fake contextual file solution did not work for me because I needed to run another webapp, and my application is also webapp.
There is a jira that will provide the best solution to our problem. See https://issues.apache.org/jira/browse/MTOMCAT-228 . Now about my decision ...
First you need to copy the war to the directory. I suggest a target directory so that it can be easily cleaned. Depending on whether you want to support the fulfillment or goals during the war, it depends on whether you copy the war or copy the war and unpack it.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>${maven-dependency-plugin.version}</version> <executions> <execution> <id>copy-war</id> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>org.foo</groupId> <artifactId>bar</artifactId> <version>${bar.version}</version> <type>war</type> <overWrite>true</overWrite> <outputDirectory>${project.build.directory}/bar/</outputDirectory> </artifactItem> </artifactItems> <stripVersion>true</stripVersion> </configuration> </execution> <execution> <id>copy-war-unpack</id> <goals> <goal>unpack</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>org.foo</groupId> <artifactId>bar</artifactId> <version>${bar.version}</version> <type>war</type> <overWrite>true</overWrite> <outputDirectory>${project.build.directory}/bar/bar</outputDirectory> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin>
Then you need to configure tomcat plugins to view the directory or war that you just copied in the previous step. Below is the configuration for tomcat 6 and 7, which is identical to the identifier of the artifact.
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>${tomcat6-maven-plugin.version}</version> <configuration> <port>8090</port> <path>${default.rice.context.path}</path> <warDirectory>${project.build.directory}/bar/bar.war</warDirectory> <warSourceDirectory>${project.build.directory}/bar/bar</warSourceDirectory> </configuration> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>${tomcat7-maven-plugin.version}</version> <configuration> <port>8090</port> <path>${default.rice.context.path}</path> <warDirectory>${project.build.directory}/bar/bar.war</warDirectory> <warSourceDirectory>${project.build.directory}/bar/bar</warSourceDirectory> </configuration> </plugin>
To be clear, you do not need to configure warDirectory or copy if you want to support tomcat: run. Conversely, you do not need to configure warSourceDirectory or you need to perform unpacking and unpacking if you want to support tomcat: run-war.
In conclusion, we note that this workaround for dependencies also works well with the Jetty Maven plugin, so if you want to support both tomcat and the pier, this may be a good way to do this.
Travis schneeberger
source share