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

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

Related

Running 2 webapps with maven Cargo?

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>

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>

Build Docker Image File of Spring Boot Application

I am trying to build a docker image for my spring boot maven project by using dockerfile-maven-plugin. I am using Docker Tool Box on windows 7 and it is running fine.
I am getting Below Error:
Failed to load Google application default credentials
java.io.IOException: The Application Default Credentials are not
available. They are available if running in Google Compute Engine.
Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS
must be defined pointing to a file defining the credentials. See
https://developers.google.com/accounts/docs/application-default-credentials
for more information.
Pom.XML Build
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.10</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<serverId>docker-hub</serverId>
<repository>${project.artifactId}</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>D:\spring\MicroServiceOutput</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
I am not able to get that why we need google default credential to build a local image.Please help me out as I am new to Docker World.
It seems that's a bug, by default the plugin set googleContainerRegistryEnabled flag to true, so you have to change that flag to false, try this:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RC2</spring-cloud.version>
<docker.image.prefix>prefix</docker.image.prefix>
<docker.image.name>${project.artifactId}</docker.image.name>
<docker.image.tag>${project.version}</docker.image.tag>
<docker.file>Dockerfile</docker.file>
</properties>
...
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.10</version>
<configuration>
<googleContainerRegistryEnabled>false</googleContainerRegistryEnabled>
<repository>${docker.image.prefix}/${docker.image.name}</repository>
<tag>${docker.image.tag}</tag>
<dockerfile>${docker.file}</dockerfile>
</configuration>
<executions>
<execution>
<id>build</id>
<goals>
<goal>build</goal>
<goal>tag</goal>
</goals>
</execution>
<execution>
<id>push</id>
<goals>
<goal>push</goal>
</goals>
</execution>
</executions>
</plugin>

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