Note that there are some explanatory texts on larger screens.

plurals
  1. POStart multiple tomcat instances with maven-tomcat-plugin
    text
    copied!<p>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.</p> <p>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.</p> <p>Here is our maven config:</p> <pre><code>&lt;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"&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;xxx&lt;/groupId&gt; &lt;artifactId&gt;XXX-SwingTests&lt;/artifactId&gt; &lt;version&gt;3.1.2-SNAPSHOT&lt;/version&gt; &lt;name&gt;XXX Swing Tests&lt;/name&gt; &lt;packaging&gt;jar&lt;/packaging&gt; &lt;properties&gt; &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt; &lt;source.encoding&gt;UTF-8&lt;/source.encoding&gt; &lt;java.compiler.version&gt;1.6&lt;/java.compiler.version&gt; &lt;XXX.version&gt;${project.version}&lt;/XXX.version&gt; &lt;swing-test.include&gt;**/ *SwingTest*&lt;/swing-test.include&gt; &lt;/properties&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;xxx&lt;/groupId&gt; &lt;artifactId&gt;XXX-Client-Base&lt;/artifactId&gt; &lt;version&gt;${XXX.version}&lt;/version&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;xxx&lt;/groupId&gt; &lt;artifactId&gt;XXX-Client-Base&lt;/artifactId&gt; &lt;version&gt;${XXX.version}&lt;/version&gt; &lt;type&gt;test-jar&lt;/type&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;junit&lt;/groupId&gt; &lt;artifactId&gt;junit&lt;/artifactId&gt; &lt;version&gt;4.8.2&lt;/version&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;abbot&lt;/groupId&gt; &lt;artifactId&gt;abbot&lt;/artifactId&gt; &lt;version&gt;1.2.0&lt;/version&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;build&gt; &lt;pluginManagement&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt; &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt; &lt;version&gt;2.0&lt;/version&gt; &lt;!-- External Libraries included in Tomcat --&gt; &lt;dependencies&gt; &lt;!-- Active MQ dependencies --&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.activemq&lt;/groupId&gt; &lt;artifactId&gt;activemq-all&lt;/artifactId&gt; &lt;version&gt;5.6.0&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;commons-logging&lt;/groupId&gt; &lt;artifactId&gt;commons-logging&lt;/artifactId&gt; &lt;version&gt;1.1.1&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;commons-collections&lt;/groupId&gt; &lt;artifactId&gt;commons-collections&lt;/artifactId&gt; &lt;version&gt;3.2.1&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;log4j&lt;/groupId&gt; &lt;artifactId&gt;log4j&lt;/artifactId&gt; &lt;version&gt;1.2.16&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-context&lt;/artifactId&gt; &lt;version&gt;3.0.6.RELEASE&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-asm&lt;/artifactId&gt; &lt;version&gt;3.0.6.RELEASE&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-beans&lt;/artifactId&gt; &lt;version&gt;3.0.6.RELEASE&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-core&lt;/artifactId&gt; &lt;version&gt;3.0.6.RELEASE&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-expression&lt;/artifactId&gt; &lt;version&gt;3.0.6.RELEASE&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.xbean&lt;/groupId&gt; &lt;artifactId&gt;xbean-spring&lt;/artifactId&gt; &lt;version&gt;3.9&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;configuration&gt; &lt;ignorePackaging&gt;true&lt;/ignorePackaging&gt; &lt;webapps&gt; &lt;webapp&gt; &lt;groupId&gt;xxx&lt;/groupId&gt; &lt;artifactId&gt;XXX-Web&lt;/artifactId&gt; &lt;version&gt;${XXX.version}&lt;/version&gt; &lt;type&gt;war&lt;/type&gt; &lt;asWebapp&gt;true&lt;/asWebapp&gt; &lt;contextPath&gt;XXX&lt;/contextPath&gt; &lt;/webapp&gt; &lt;/webapps&gt; &lt;systemProperties&gt; &lt;!-- Allow Slashes and backslashes encoding --&gt; &lt;org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH&gt;true&lt;/org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH&gt; &lt;org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH&gt;true&lt;/org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH&gt; &lt;/systemProperties&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/pluginManagement&gt; &lt;resources&gt; &lt;resource&gt; &lt;directory&gt;src/main/resources&lt;/directory&gt; &lt;filtering&gt;true&lt;/filtering&gt; &lt;includes&gt; &lt;include&gt;*&lt;/include&gt; &lt;/includes&gt; &lt;/resource&gt; &lt;resource&gt; &lt;directory&gt;src/main/resources&lt;/directory&gt; &lt;filtering&gt;false&lt;/filtering&gt; &lt;excludes&gt; &lt;exclude&gt;*&lt;/exclude&gt; &lt;/excludes&gt; &lt;/resource&gt; &lt;resource&gt; &lt;directory&gt;src/main/conf&lt;/directory&gt; &lt;filtering&gt;true&lt;/filtering&gt; &lt;/resource&gt; &lt;/resources&gt; &lt;testResources&gt; &lt;testResource&gt; &lt;filtering&gt;false&lt;/filtering&gt; &lt;directory&gt;src/test/resources&lt;/directory&gt; &lt;includes&gt; &lt;include&gt;**/*&lt;/include&gt; &lt;/includes&gt; &lt;excludes&gt; &lt;exclude&gt;**/*.xml&lt;/exclude&gt; &lt;/excludes&gt; &lt;/testResource&gt; &lt;testResource&gt; &lt;filtering&gt;true&lt;/filtering&gt; &lt;directory&gt;src/test/resources&lt;/directory&gt; &lt;includes&gt; &lt;include&gt;**/*.xml&lt;/include&gt; &lt;/includes&gt; &lt;/testResource&gt; &lt;/testResources&gt; &lt;/build&gt; &lt;profiles&gt; &lt;!-- Profile that starts the tomcat servers --&gt; &lt;profile&gt; &lt;id&gt;start-servers&lt;/id&gt; &lt;activation&gt; &lt;activeByDefault&gt;true&lt;/activeByDefault&gt; &lt;/activation&gt; &lt;build&gt; &lt;plugins&gt; &lt;!-- Run CL server --&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt; &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;tomcat-run-CL&lt;/id&gt; &lt;goals&gt; &lt;goal&gt;run-war-only&lt;/goal&gt; &lt;/goals&gt; &lt;phase&gt;pre-integration-test&lt;/phase&gt; &lt;configuration&gt; &lt;port&gt;8180&lt;/port&gt; &lt;ajpPort&gt;8109&lt;/ajpPort&gt; &lt;fork&gt;true&lt;/fork&gt; &lt;systemProperties&gt; &lt;config_XXX_application&gt;${project.build.directory}/test-classes/central/application.properties&lt;/config_XXX_application&gt; &lt;config_XXX_cron_application&gt;${project.build.directory}/test-classes/central/cron.properties&lt;/config_XXX_cron_application&gt; &lt;config_XXX_external&gt;${project.build.directory}/test-classes/central/external-providers.properties&lt;/config_XXX_external&gt; &lt;/systemProperties&gt; &lt;contextFile&gt;${project.build.directory}/classes/CL/context.xml&lt;/contextFile&gt; &lt;configurationDir&gt;${project.build.directory}/tomcat-cl&lt;/configurationDir&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;!-- Run LL server --&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt; &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;tomcat-run-LL&lt;/id&gt; &lt;goals&gt; &lt;goal&gt;run-war-only&lt;/goal&gt; &lt;/goals&gt; &lt;phase&gt;pre-integration-test&lt;/phase&gt; &lt;configuration&gt; &lt;port&gt;8280&lt;/port&gt; &lt;ajpPort&gt;8209&lt;/ajpPort&gt; &lt;fork&gt;true&lt;/fork&gt; &lt;systemProperties&gt; &lt;config_XXX_application&gt;${project.build.directory}/test-classes/local/application.properties&lt;/config_XXX_application&gt; &lt;config_XXX_cron_application&gt;${project.build.directory}/test-classes/local/cron.properties&lt;/config_XXX_cron_application&gt; &lt;config_XXX_external&gt;${project.build.directory}/test-classes/local/external-providers.properties&lt;/config_XXX_external&gt; &lt;/systemProperties&gt; &lt;contextFile&gt;${project.build.directory}/classes/LL/context.xml&lt;/contextFile&gt; &lt;configurationDir&gt;${project.build.directory}/tomcat-ll&lt;/configurationDir&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;!-- Run OL server --&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt; &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;tomcat-run-OL&lt;/id&gt; &lt;goals&gt; &lt;goal&gt;run-war-only&lt;/goal&gt; &lt;/goals&gt; &lt;phase&gt;pre-integration-test&lt;/phase&gt; &lt;configuration&gt; &lt;port&gt;8380&lt;/port&gt; &lt;ajpPort&gt;8309&lt;/ajpPort&gt; &lt;fork&gt;true&lt;/fork&gt; &lt;systemProperties&gt; &lt;config_XXX_application&gt;${project.build.directory}/test-classes/operational/application.properties&lt;/config_XXX_application&gt; &lt;config_XXX_cron_application&gt;${project.build.directory}/test-classes/operational/cron.properties&lt;/config_XXX_cron_application&gt; &lt;config_XXX_external&gt;${project.build.directory}/test-classes/operational/external-providers.properties&lt;/config_XXX_external&gt; &lt;/systemProperties&gt; &lt;contextFile&gt;${project.build.directory}/classes/OL/context.xml&lt;/contextFile&gt; &lt;configurationDir&gt;${project.build.directory}/tomcat-ol&lt;/configurationDir&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;!-- Stop all servers --&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt; &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;tomcat-shutdown&lt;/id&gt; &lt;goals&gt; &lt;goal&gt;shutdown&lt;/goal&gt; &lt;/goals&gt; &lt;phase&gt;post-integration-test&lt;/phase&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;/profile&gt; &lt;!-- Profile that runs the swing tests in the integration-test phase --&gt; &lt;profile&gt; &lt;id&gt;swing-tests&lt;/id&gt; &lt;activation&gt; &lt;activeByDefault&gt;true&lt;/activeByDefault&gt; &lt;/activation&gt; &lt;build&gt; &lt;plugins&gt; &lt;!-- Execute swing tests in the 'integration-test' phase --&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt; &lt;version&gt;2.13&lt;/version&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;integration-test&lt;/id&gt; &lt;phase&gt;integration-test&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;integration-test&lt;/goal&gt; &lt;goal&gt;verify&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;argLine&gt;-Xms512m -Xmx1024m -XX:MaxPermSize=512m&lt;/argLine&gt; &lt;includes&gt; &lt;include&gt;${swing-test.include}&lt;/include&gt; &lt;/includes&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;/profile&gt; &lt;/profiles&gt; &lt;/project&gt; </code></pre> <p>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.</p> <p>Do you have any idea of what's wrong with this configuration? What is the proper way to achieve what we're trying here?</p> <p>Edit: Well actually, there's an error in the logs, but I'm not sure how to understand that:</p> <pre><code>[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) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload