Reputation: 1207
we need to start 3 tomcats with the same web-application but different configuration (injected through spring + system properties) in order to execute some integration tests of a swing application.
We have a maven project dedicated for this testing that fetches both the WAR for the server-side app and the JAR for the swing app, starts 3 tomcat instances on 3 different sets of ports, deploys the WAR in those tomcats and runs the tests.
Here is our maven config:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxx</groupId>
<artifactId>XXX-SwingTests</artifactId>
<version>3.1.2-SNAPSHOT</version>
<name>XXX Swing Tests</name>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<source.encoding>UTF-8</source.encoding>
<java.compiler.version>1.6</java.compiler.version>
<XXX.version>${project.version}</XXX.version>
<swing-test.include>**/ *SwingTest*</swing-test.include>
</properties>
<dependencies>
<dependency>
<groupId>xxx</groupId>
<artifactId>XXX-Client-Base</artifactId>
<version>${XXX.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xxx</groupId>
<artifactId>XXX-Client-Base</artifactId>
<version>${XXX.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>abbot</groupId>
<artifactId>abbot</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<!-- External Libraries included in Tomcat -->
<dependencies>
<!-- Active MQ dependencies -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>3.9</version>
</dependency>
</dependencies>
<configuration>
<ignorePackaging>true</ignorePackaging>
<webapps>
<webapp>
<groupId>xxx</groupId>
<artifactId>XXX-Web</artifactId>
<version>${XXX.version}</version>
<type>war</type>
<asWebapp>true</asWebapp>
<contextPath>XXX</contextPath>
</webapp>
</webapps>
<systemProperties>
<!-- Allow Slashes and backslashes encoding -->
<org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH>true</org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH>
<org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH>true</org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH>
</systemProperties>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/conf</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<filtering>false</filtering>
<directory>src/test/resources</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/*.xml</exclude>
</excludes>
</testResource>
<testResource>
<filtering>true</filtering>
<directory>src/test/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</testResource>
</testResources>
</build>
<profiles>
<!-- Profile that starts the tomcat servers -->
<profile>
<id>start-servers</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<!-- Run CL server -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<executions>
<execution>
<id>tomcat-run-CL</id>
<goals>
<goal>run-war-only</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<port>8180</port>
<ajpPort>8109</ajpPort>
<fork>true</fork>
<systemProperties>
<config_XXX_application>${project.build.directory}/test-classes/central/application.properties</config_XXX_application>
<config_XXX_cron_application>${project.build.directory}/test-classes/central/cron.properties</config_XXX_cron_application>
<config_XXX_external>${project.build.directory}/test-classes/central/external-providers.properties</config_XXX_external>
</systemProperties>
<contextFile>${project.build.directory}/classes/CL/context.xml</contextFile>
<configurationDir>${project.build.directory}/tomcat-cl</configurationDir>
</configuration>
</execution>
</executions>
</plugin>
<!-- Run LL server -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<executions>
<execution>
<id>tomcat-run-LL</id>
<goals>
<goal>run-war-only</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<port>8280</port>
<ajpPort>8209</ajpPort>
<fork>true</fork>
<systemProperties>
<config_XXX_application>${project.build.directory}/test-classes/local/application.properties</config_XXX_application>
<config_XXX_cron_application>${project.build.directory}/test-classes/local/cron.properties</config_XXX_cron_application>
<config_XXX_external>${project.build.directory}/test-classes/local/external-providers.properties</config_XXX_external>
</systemProperties>
<contextFile>${project.build.directory}/classes/LL/context.xml</contextFile>
<configurationDir>${project.build.directory}/tomcat-ll</configurationDir>
</configuration>
</execution>
</executions>
</plugin>
<!-- Run OL server -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<executions>
<execution>
<id>tomcat-run-OL</id>
<goals>
<goal>run-war-only</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<port>8380</port>
<ajpPort>8309</ajpPort>
<fork>true</fork>
<systemProperties>
<config_XXX_application>${project.build.directory}/test-classes/operational/application.properties</config_XXX_application>
<config_XXX_cron_application>${project.build.directory}/test-classes/operational/cron.properties</config_XXX_cron_application>
<config_XXX_external>${project.build.directory}/test-classes/operational/external-providers.properties</config_XXX_external>
</systemProperties>
<contextFile>${project.build.directory}/classes/OL/context.xml</contextFile>
<configurationDir>${project.build.directory}/tomcat-ol</configurationDir>
</configuration>
</execution>
</executions>
</plugin>
<!-- Stop all servers -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<executions>
<execution>
<id>tomcat-shutdown</id>
<goals>
<goal>shutdown</goal>
</goals>
<phase>post-integration-test</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Profile that runs the swing tests in the integration-test phase -->
<profile>
<id>swing-tests</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<!-- Execute swing tests in the 'integration-test' phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.13</version>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<argLine>-Xms512m -Xmx1024m -XX:MaxPermSize=512m</argLine>
<includes>
<include>${swing-test.include}</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Even though the logs don't show anything particular, only the tests that target the server started first succeed, others fail and I haven't been able to see why (I suspect that the spring context was incorrectly started, but I couldn't be sure). If I comment out the first plugin execution, then all tests that target this server now fail (obviously), but the tests that target the next one in the list now pass.
Do you have any idea of what's wrong with this configuration? What is the proper way to achieve what we're trying here?
Edit: Well actually, there's an error in the logs, but I'm not sure how to understand that:
[INFO] [tomcat7:run-war-only {execution: tomcat-run-CL}]
[INFO] Running war on http://localhost:8180/xxx-SwingTests
[INFO] Creating Tomcat server configuration at C:\projects\xxx\workspace\xxx-SwingTests\target\tomcat-cl
[INFO] setting SystemProperties:
[INFO] config_xxx_application=C:\projects\xxx\workspace\xxx-SwingTests\target/test-classes/central/application.properties
[INFO] config_xxx_cron_application=C:\projects\xxx\workspace\xxx-SwingTests\target/test-classes/central/cron.properties
[INFO] config_xxx_external=C:\projects\xxx\workspace\xxx-SwingTests\target/test-classes/central/external-providers.properties
[INFO] org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true
[INFO] org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
[INFO] create webapp with contextPath: /xxx-SwingTests
[INFO] Deploying dependency wars
[INFO] Deploy warfile: C:\Users\Administrator\.m2\repository\xxx\xxx-Web\3.1.2-SNAPSHOT\xxx-Web-3.1.2-SNAPSHOT.war to contextPath: /xxx
Jan 9, 2013 7:44:27 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8180"]
Jan 9, 2013 7:44:27 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8109"]
Jan 9, 2013 7:44:27 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Jan 9, 2013 7:44:27 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.30
Jan 9, 2013 7:44:27 PM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base C:\projects\xxx\workspace\xxx-SwingTests\target\xxx-SwingTests-3.1.2-SNAPSHOT does not exist or is not a readable directory
at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:140)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4906)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5086)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Jan 9, 2013 7:44:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error in resourceStart()
Jan 9, 2013 7:44:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error getConfigured
Jan 9, 2013 7:44:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/xxx-SwingTests] startup failed due to previous errors
Jan 9, 2013 7:44:27 PM org.apache.catalina.deploy.NamingResources cleanUp
WARNING: Failed to retrieve JNDI naming context for container [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/xxx-SwingTests]] so no cleanup was performed for that container
javax.naming.NameNotFoundException: Name [comp/env] is not bound in this Context. Unable to find [comp].
at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at org.apache.catalina.deploy.NamingResources.cleanUp(NamingResources.java:988)
at org.apache.catalina.deploy.NamingResources.stopInternal(NamingResources.java:970)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5495)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Upvotes: 1
Views: 1856
Reputation: 2072
How about just using Jetty + Tomcat?
You are not able to use Tomcat for as much instances as you want with plugin. However, you can use maven-jetty-plugin to start at least 2 applications at the same time.
Upvotes: 0
Reputation: 2310
The issue is starting twice a jndi context in the same classloader this is not currently possible with tomcat.
Upvotes: 1