Reputation: 10938
I need to start up a jetty with an external (possibly remote) .war file (App T) as web app resource from inside my test so that my system under test (App A) can connect to it to run calls against its REST interface.
I found a lot of tutorials about how to start a jetty for the war of the system under test (App A). I also found some about how to have maven start jetty for an external .war (App T) as part of the build cycle. However I can't figure out if it's possible to do the above.
Ideally I add the AppT project as maven dependency and access it via classpath.
Upvotes: 1
Views: 1840
Reputation: 32717
Well, I don't know how you would go about doing it, if it was a remote war file (you'd probably need to download it first before the execution of the jetty plugin), but here's how to do it, when you've already got it somewhere on your file system:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${version.jetty}</version>
<configuration>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>${project.build.directory}/webapps/foo-bar.war</war>
<contextPath>/foo</contextPath>
</contextHandler>
</contextHandlers>
</configuration>
</plugin>
My advice is to add that war as a dependency with scope:provided.
<dependencies>
<!-- Webapps which will not be included in the final WAR artifact: -->
<dependency>
<groupId>com.foo.bar</groupId>
<artifactId>foo-bar</artifactId>
<version>${version.foo.bar}</version>
<type>war</type>
<scope>provided</scope>
</dependency>
</dependencies>
In addition, you will most-likely need something like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<!-- Used to copy the foo bar war to the webapps folder -->
<id>copy-dependency-foo-bar</id>
<phase>process-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.foo.bar</groupId>
<artifactId>foo-bar</artifactId>
<version>${version.foo.bar}</version>
<type>war</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/webapps</outputDirectory>
<destFileName>foo-bar.war</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
This last bit above will make sure that the resolved artifact is copied over to your target directory's webapps sub-folder before the jetty plugin has attempted to load it.
Upvotes: 3