I am trying to use "tomcat7-maven-plugin" to run integration test on war file. WHen the war gets dployed it basically load spring applicaitoncontext which in turns expect property files on classpath. In regular tomcat instance I keep property files somewhere on my machine and then configure catalina.properties -> common.loader to point to that directory. But I don't know how to achieve that with this plugin.
here's the plugin config I tried:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<!-- port>8090</port -->
<url>http://localhost:8080/manager/text</url>
<server>TomcatServer</server>
<path>/${project.build.finalName}</path>
<!-- systemProperties>
<systemProperty>
<maven.tomcat.port>8080</maven.tomcat.port>
</systemProperty>
</systemProperties -->
<!-- if you want to use test dependencies rather than only runtime -->
<useTestClasspath>false</useTestClasspath>
<!-- optional if you want to add some extra directories into the classloader -->
<additionalClasspathDirs>
<additionalClasspathDir>${basedir}/src/test/resources</additionalClasspathDir>
</additionalClasspathDirs>
<additionalConfigFilesDir>${basedir}/src/test/resources</additionalConfigFilesDir>
</configuration>
<executions>
<execution>
<id>tomcat-run</id>
<phase>pre-integration-test</phase>
<goals>
<!-- goal>run</goal -->
<goal>run-war-only</goal>
</goals>
<configuration>
<additionalClasspathDirs>
<additionalClasspathDir>${basedir}/src/test/resources</additionalClasspathDir>
</additionalClasspathDirs>
<additionalConfigFilesDir>${basedir}/src/test/resources</additionalConfigFilesDir>
</configuration>
</execution>
<execution>
<id>tomcat-shutdown</id>
<goals>
<goal>shutdown</goal>
</goals>
<phase>post-integration-test</phase>
</execution>
</executions>
</plugin>
We encountered same problem. I filed a JIRA for that (MTOMCAT-246). Turns out it works that way only for tomcat7:run goal, not for the run-war-only. They plan to fix it in the 3.0 release. We have a workaround for that in place, see below.
One way to achieve it is to package your property files as jar file and include them in the dependencies of the plugin.
In our case that meant creating a maven module out of our config folder in the parent project (which stored configs for various environments):
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>distribution.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<!-- add property replacement to state environment name -->
<directory>build</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
The distribution.xml looked like:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>config</id>
<formats>
<format>jar</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.properties</include>
<include>*.xml</include>
</includes>
</fileSet>
</fileSets>
</assembly>
And then in the plugin section:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
....
<dependencies>
<dependency>
<groupId>com.your.project</groupId>
<artifactId>config</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
You add a link to the config.jar file which contains those property files.
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