This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin> | |
<groupId>org.mortbay.jetty</groupId> | |
<artifactId>maven-jetty-plugin</artifactId> | |
<version>6.1.26</version> | |
<configuration> | |
<scanIntervalSeconds>10</scanIntervalSeconds> | |
<stopKey>foo</stopKey> | |
<stopPort>9999</stopPort> | |
</configuration> | |
<executions> | |
<execution> | |
<id>start-jetty</id> | |
<phase>pre-integration-test</phase> | |
<goals> | |
<goal>run</goal> | |
</goals> | |
<configuration> | |
<scanIntervalSeconds>0</scanIntervalSeconds> | |
<daemon>true</daemon> | |
</configuration> | |
</execution> | |
<execution> | |
<id>stop-jetty</id> | |
<phase>post-integration-test</phase> | |
<goals> | |
<goal>stop</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> |
Also starting any external WAR artifact is straight forward with the maven-jetty-plugin and the deploy-war goal.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin> | |
<groupId>org.mortbay.jetty</groupId> | |
<artifactId>maven-jetty-plugin</artifactId> | |
<version>6.1.26</version> | |
<configuration> | |
<scanIntervalSeconds>10</scanIntervalSeconds> | |
<stopKey>foo</stopKey> | |
<stopPort>9999</stopPort> | |
<contextPath>/</contextPath> | |
<webApp> | |
/your/path/to/the/external.war | |
</webApp> | |
</configuration> | |
<executions> | |
<execution> | |
<id>start-jetty</id> | |
<phase>pre-integration-test</phase> | |
<goals> | |
<goal>deploy-war</goal> | |
</goals> | |
<configuration> | |
<scanIntervalSeconds>0</scanIntervalSeconds> | |
<daemon>true</daemon> | |
</configuration> | |
</execution> | |
<execution> | |
<id>stop-jetty</id> | |
<phase>post-integration-test</phase> | |
<goals> | |
<goal>stop</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> |
As you can see, the version is hard-coded in the path. This is somewhat ok as long as you are not violating the DRY principle. If you use the version somewhere else in your pom.xml, make sure to use a custom Maven property. Another way, which is a bit nicer perhaps, is to use the cargo-maven2-plugin which out of the box can start the WAR artifact of any Maven dependency from within the dependencies section. Here is a nice example from stackoverflow.com.
As you can see, either the cargo-maven2-plugin or the maven-jetty-plugin can be used for the simple use cases. It gets a bit trickier if you want to start the external WAR artifact and set some System properties during startup of the container. Both the maven-jetty-plugin and the cargo-maven2-plugin allow you to define individual system properties. However, only the maven-jetty-plugin can read a pre-existing properties file instead of individual System properties. This was required in one of the projects I am working on. Copying all the System properties out of the properties file to add them as individual System properties, is a lot of work and would again violate the DRY principle.
Also sometimes when you are developing both the service and the client project, and you are not using the SNAPSHOT mechanism, it can be tedious to update the version of the server WAR artifact that gets started during the integration tests of the client project. Maven knows two fixed keywords which you can use instead of specifying an exact version or a range. Use LATEST to download the latest snapshot or released version of a dependency from a repository. Use RELEASE to download the latest released version of a dependency from a dependency. Unfortunately you cannot use LATEST or RELEASE to start a WAR artifact of a dependency, if you are using the maven-jetty-plugin. This is because you specify the location of the WAR artifact as a full path inside the configuration - webApp element of the maven-jetty-plugin. The plugin does not use the syntax which is used to define the Maven dependencies.
There is however a little trick. You use the maven-dependency-plugin, which uses the default syntax for dependencies and can understand LATEST and RELEASE, to copy the WAR artifact to a fixed location. While copying you should also rename the war file. This makes your life easier as you never have to adapt the path in the webApp element of the maven-jetty-plugin if the version changes. Here is an example:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-dependency-plugin</artifactId> | |
<version>2.3</version> | |
<executions> | |
<execution> | |
<id>copy-war-to-lib-folder</id> | |
<phase>process-sources</phase> | |
<goals> | |
<goal>copy</goal> | |
</goals> | |
<configuration> | |
<artifactItems> | |
<artifactItem> | |
<groupId>external.war.group</groupId> | |
<artifactId>external-war-artifact</artifactId> | |
<version>LATEST</version> | |
<type>war</type> | |
<overWrite>true</overWrite> | |
<outputDirectory>${project.build.directory}/lib</outputDirectory> | |
<destFileName>${renamed.war}</destFileName> | |
</artifactItem> | |
</artifactItems> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
<plugin> | |
<groupId>org.mortbay.jetty</groupId> | |
<artifactId>maven-jetty-plugin</artifactId> | |
<version>6.1.26</version> | |
<configuration> | |
<scanIntervalSeconds>10</scanIntervalSeconds> | |
<stopKey>foo</stopKey> | |
<stopPort>9999</stopPort> | |
<contextPath>/</contextPath> | |
<webApp> | |
${project.build.directory}/lib/${renamed.war} | |
</webApp> | |
<systemPropertiesFile>${project.build.testOutputDirectory}/some-existing.properties</systemPropertiesFile> | |
</configuration> | |
<executions> | |
<execution> | |
<id>start-jetty</id> | |
<phase>pre-integration-test</phase> | |
<goals> | |
<goal>deploy-war</goal> | |
</goals> | |
<configuration> | |
<scanIntervalSeconds>0</scanIntervalSeconds> | |
<daemon>true</daemon> | |
</configuration> | |
</execution> | |
<execution> | |
<id>stop-jetty</id> | |
<phase>post-integration-test</phase> | |
<goals> | |
<goal>stop</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> |