Running 2 webapps with maven Cargo? - maven

I've got 2 applications (as WAR files) that I need to run on pre-integration phase before executing my test scenarios.
I've already configure the maven cargo plugin like this :
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven3-plugin</artifactId>
<version>1.9.8</version>
<executions>
<execution>
<id>neo-start-lanceur</id>
<phase>pre-integration-test</phase>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<artifactInstaller>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat</artifactId>
<version>8.5.9</version>
</artifactInstaller>
</container>
<configuration>
<properties>
<cargo.servlet.port>8081</cargo.servlet.port>
<spring.profiles.active>tdc</spring.profiles.active>
<JAVA_OPTS>-Xms512m -Xmx1536m -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=70</JAVA_OPTS>
</properties>
<home>${project.build.directory}/neo-lanceur</home>
</configuration>
<deployables>
<deployable>
<groupId>fr.cnp.neo</groupId>
<artifactId>neo-web-lanceur</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>neo-stop-lanceur</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
<execution>
<id>neo-start-webapp</id>
<phase>pre-integration-test</phase>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<artifactInstaller>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat8</artifactId>
<version>8.5.9</version>
</artifactInstaller>
</container>
<configuration>
<properties>
<cargo.servlet.port>8080</cargo.servlet.port>
<spring.profiles.active>tdc</spring.profiles.active>-->
<JAVA_OPTS>-Xms512m -Xmx1536m -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=70</JAVA_OPTS>
</properties>
<home>${project.build.directory}/neo-webapp</home>
<configfiles>
<configfile>
<file>${project.basedir}/../web/src/test/conf/neo.properties</file>
<todir>webapps/neo-web/WEB-INF</todir>
</configfile>
</configfiles>
</configuration>
<deployables>
<deployable>
<groupId>fr.cnp.neo</groupId>
<artifactId>neo-web</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>neo-stop-webapp</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
But it deployes and run only the first application.
Is it possible to deploy 2 WARs on a single tomcat instance or to create 2 local containers?
Thanks for your help !!

You can deploy both WARs on a single Tomcat instance by placing them into <deployables> section:
<deployables>
<deployable>
<groupId>fr.cnp.neo</groupId>
<artifactId>neo-web-lanceur</artifactId>
<type>war</type>
</deployable>
<deployable>
<groupId>fr.cnp.neo</groupId>
<artifactId>neo-web</artifactId>
<type>war</type>
</deployable>
</deployables>

Related

How to run embedded Tomcat 9 inside Maven 3 for integration testing purposes?

I am trying to run embedded Tomcat 9 inside Maven 3 for integration testing purposes. I was led to cargo-maven2-plugin by other SO answers.
So, attempting to follow the instructions found here:
https://codehaus-cargo.github.io/cargo/Static+deployment+of+WAR.html
I have this fragment in a simple POM:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.7.6</version>
<configuration>
<container>
<containerId>tomcat9x</containerId>
<type>embedded</type>
</container>
<deployables>
<deployable>
<type>war</type>
<properties>
<file>path/to/myapp.war</file>
</properties>
</deployable>
</deployables>
</configuration>
</plugin>
</plugins>
</build>
Which I try to execute with mvn org.codehaus.cargo:cargo-maven2-plugin:run
It fails with the error:
[INFO] [en2.ContainerRunMojo] Resolved container artifact
org.codehaus.cargo:cargo-core-container-tomcat:jar:1.7.6 for container
tomcat9x [WARNING] The defined deployable has the same groupId and
artifactId as your project's main artifact but the type is different.
You've defined a [war] type wher eas the project's packaging is [pom].
This is possibly an error and as a consequence the plugin will try to
find this deployable in the project's dependencies.
How can I make this work? I just want to launch the given WAR in an embedded tomcat9, from within Maven.
After trying many permutations, this finally worked for me:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.7.9</version>
<configuration>
<container>
<systemProperties>
<myvar1>${myEnvVar}</myvar1>
<myvar2>... stuff ...</myvar2>
</systemProperties>
<containerId>tomcat9x</containerId>
<zipUrlInstaller>
<url>https://repo.maven.apache.org/maven2/org/apache/tomcat/tomcat/9.0.29/tomcat-9.0.29.zip</url>
</zipUrlInstaller>
</container>
<deployables>
<deployable>
<groupId>org.codehaus.cargo</groupId>
<artifactId>simple-war</artifactId>
<type>war</type>
<location>path/to/myapp.war</location>
<properties>
<context>myapp</context>
</properties>
</deployable>
</deployables>
<executions>
<execution>
<id>start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
Use the failsafe plugin to automatically run the Integration Tests between the start and stop:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>

maven-deploy-plugin not executing its execution

I need to deploy custom jar's from my project itself I overrides maven-deploy-plugin with two more execution with its default execution. below are my pom.xml with distributionManagement and maven-deploy-plugin which I use for my deployment.
<groupId>mycompany</groupId>
<artifactId>myproject</artifactId>
<packaging>jar</packaging>
<distributionManagement>
<repository>
<id>temp</id>
<name>Release Repository</name>
<url>http://localhost:8000/nexus/content/repositories/temp/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
some dependency
</dependency>
<dependency>
some dependency
</dependency>
<dependency>
some dependency
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
<execution>
<id>myjar-one</id>
<phase>deploy</phase>
<configuration>
<repositoryId>temp</repositoryId>
<url>http://localhost:8000/nexus/content/repositories/temp/</url>
<packaging>jar</packaging>
<artifactId>myjar-one</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<sources>${project.build.directory}/build/lib/myjar-one.jar</sources>
</configuration>
</execution>
<execution>
<id>myjar-two</id>
<phase>deploy</phase>
<configuration>
<repositoryId>temp</repositoryId>
<url>http://localhost:8000/nexus/content/repositories/temp/</url>
<packaging>jar</packaging>
<artifactId>myjar-two</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<sources>${project.build.directory}/build/lib/myjar-two.jar</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Guys I figure out the issue, there are following thing I need to fix.
Need to add goal.
Need to use file tag instead of source tag.
So final maven-deploy-plugin looks like.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
<execution>
<id>myjar-one</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<repositoryId>temp</repositoryId>
<url>http://localhost:8000/nexus/content/repositories/temp/</url>
<packaging>jar</packaging>
<artifactId>myjar-one</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${project.build.directory}/build/lib/myjar-one.jar</file>
</configuration>
</execution>
<execution>
<id>myjar-two</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<repositoryId>temp</repositoryId>
<url>http://localhost:8000/nexus/content/repositories/temp/</url>
<packaging>jar</packaging>
<artifactId>myjar-two</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${project.build.directory}/build/lib/myjar-two.jar</file>
</configuration>
</execution>
</executions>
</plugin>
after fixing this issue, my both custom jar's are deployed at my maven repository. Thanks for help

Tomcat-users.xml is rewritten on container restart - how do I supply credentials?

Im using cargo to deploy a war file to a tomcat server. I'm unable to login to the manager however as conf/tomcat-users.xml is rewritten when I start the container ie
mvn cargo:run
how I can supply user/password creds to access the manager?
cheers!
Edit: Cargo configuration
<plugins>
<!-- Start's the plugin tag for Cargo! -->
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>false</wait>
<container>
<containerId>tomcat${tomcat.major}x</containerId>
<zipUrlInstaller>
<url>http://archive.apache.org/dist/tomcat/tomcat-${tomcat.major}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz</url>
<extractDir>${project.build.directory}/extract/</extractDir>
<downloadDir>${project.build.directory}/download/</downloadDir>
</zipUrlInstaller>
<output>${project.build.directory}/tomcat${tomcat.major}x.log</output>
<log>${project.build.directory}/cargo.log</log>
</container>
<configuration>
<home>${project.build.directory}/tomcat-${tomcat.version}/container</home>
<properties>
<cargo.logging>high</cargo.logging>
<cargo.servlet.port>9080</cargo.servlet.port>
<cargo.tomcat.ajp.port>9008</cargo.tomcat.ajp.port>
</properties>
</configuration>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
<configuration>
<deployer>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>mod-war</artifactId>
<type>war</type>
<pingURL>http://localhost:9080/mod-war</pingURL>
<pingTimeout>30000</pingTimeout>
<properties>
<context>mod-war</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
Found it. You can supply custom configuration through the following xml (link to cargo docs in the above comments)
<files>
<copy>
<file>tomcat-users.xml</file>
<tofile>conf/tomcat-users.xml</tofile>
<configfile>true</configfile>
<overwrite>true</overwrite>
</copy>
</files>
So you can specify your own conf/*.xml or anything else and it will be copied before the container starts. I can login to the manager now :)
Cheers

Maven cargo jetty6x: is it possible to provide additional Jetty configuration?

I have application launched using maven cargo plugin with jetty6x. I get HTTP/1.1 413 FULL head on certain requests. I found out, that I need to specify larger headerBufferSize (due to large request header size). Is there a way to provide it to the cargo configuration?
My cargo configuration:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.1.2</version>
<configuration>
<contextPath>/${jetty.admin.context}</contextPath>
<container>
<containerId>jetty6x</containerId>
<type>embedded</type>
</container>
<configuration>
<properties>
<cargo.servlet.port>${jetty.port}</cargo.servlet.port>
</properties>
<deployables>
<deployable>
<properties>
<context>/http</context>
</properties>
<groupId>xxx.xxx.server</groupId>
<artifactId>http</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
<wait>false</wait>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
You want to specify the additional configuration files and the directories where they go under
<configuration><configfiles>...
in the configuration of the cargo plugin
see this post or the cargo site.

Maven: How do I configure tests to run in integration-test phase?

I'm using Maven 3.0.3. I want to run some Junit tests in my test phase and others in my integration-test phase. Problem is nothing is running during the integration-test phase. I run the command
mvn clean install
to kick everything off. Here is how I've configured my surefire-plugin ...
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<skip>false</skip>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
<additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
</additionalClasspathElements>
<useManifestOnlyJar>false</useManifestOnlyJar>
<forkMode>always</forkMode>
<systemProperties>
<property>
<name>gwt.args</name>
<value>-out \${webAppDirectory}</value>
</property>
</systemProperties>
<excludes>
<exclude>**/integration/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/integration/**</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
I have two JUnit tests in my "integration" directory. I'm using the Maven Cargo plugin to spin up a server during the integration phase. Here is that configuration ...
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>tomcat${tomcat.major}x</containerId>
<zipUrlInstaller>
<url>http://archive.apache.org/dist/tomcat/tomcat-${tomcat.major}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz</url>
<downloadDir>${project.build.directory}/downloads</downloadDir>
<extractDir>${project.build.directory}/extracts</extractDir>
</zipUrlInstaller>
<output>${project.build.directory}/tomcat${tomcat.major}x.log</output>
<log>${project.build.directory}/cargo.log</log>
</container>
<configuration>
<home>${project.build.directory}/tomcat-${tomcat.version}/container</home>
<properties>
<cargo.logging>high</cargo.logging>
<cargo.servlet.port>${tomcat.servlet.port}</cargo.servlet.port>
<cargo.tomcat.ajp.port>${tomcat.ajb.port}</cargo.tomcat.ajp.port>
</properties>
</configuration>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
<configuration>
<deployer>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<type>war</type>
<pingURL>http://localhost:${tomcat.servlet.port}/${project.artifactId}</pingURL>
<pingTimeout>30000</pingTimeout>
<properties>
<context>${project.artifactId}</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Any ideas how I change/enhance my configuration so that my integration tests will run? - Dave
Have a look at Maven Failsafe Plugin

Resources