Using a custom web.xml in cargo-maven3-plugin

32 views
Skip to first unread message

Krishna Revuru

unread,
Nov 23, 2024, 10:35:12 AM11/23/24
to Codehaus Cargo
Hello Cargo Team - Salutations,
Thanks for the outstanding plugin to make life easy for me.
Coming to my issue: I have the below setup that works fine, where I have configued most of it:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven3-plugin</artifactId>
<version>1.10.15</version>
<configuration>
<deployables>
<deployable>
<location>${project.build.directory}/${project.build.finalName}.war</location>
<properties>
<context>/MyService</context>
</properties>
</deployable>
</deployables>
<container>
<containerId>tomcat9x</containerId>
<home>${project.basedir}/src/test/resources/local/apache-tomcat</home>
<type>installed</type>
<timeout>300000</timeout>
</container>
<configuration>
<properties>
<cargo.jvmargs>
-Xms1024m -Xmx2048m
-- add-opens java.base/java.io=ALL-UNNAMED
-- add-opens java.base/java.net=ALL-UNNAMED
-- add-opens java.base/java.nio=ALL-UNNAMED
-- add-opens java.base/java.util=ALL-UNNAMED
-- add-opens java.base/java.lang=ALL-UNNAMED
-- add-opens java.base/java.time=ALL-UNNAMED
-- add-opens java.base/java.math=ALL-UNNAMED
-- add-opens java.base/sun.util.calendar=ALL-UNNAMED
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005
-cp ${project.basedir}/src/test/resources/local/
-DConfigFile=${project.basedir}/src/test/resources/local/MyService.cfg
</cargo.jvmargs>
<cargo.servlet.port>8080</cargo.servlet.port>
<cargo.tomcat.shutdown.port>8205</cargo.tomcat.shutdown.port>
<cargo.servlet.users>myuser1:mypass1:tomcat,myrole|myuser2:mypass2:tomcat,myrole|myuser3:mypass3:tomcat,myrole|</cargo.servlet.users>
</properties>
</configuration>
</configuration>
</plugin>
With the above, I can run my webapp locally.
But for one issue.
In my web.xml I need this for my local to run, and not when deployed onto our environment box:
<!-- For Dev Only Authentication
<security-constraint>
<web-resource-collection>
<web-resource-name>protected-area</web-resource-name>
<url-pattern>/*< /url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>myrole</role-name>
</auth-constraint>
</security-constraint>

<login-config>
<auth-method>BASIC</auth-method>
<realm-name>myrealm</realm-name>
</login-config>

<security-role>
<description>The CFO Users</description>
<role-name>myrole</role-name>
</security-role> -->
So everytime I checkout my git branch, I uncomment this in my web.xml to do my local testing and revert this back before I commit/push my dev changes.
<!-- For Dev Only Authentication  -->
<security-constraint>
<web-resource-collection>
<web-resource-name>protected-area</web-resource-name>
<url-pattern>/*< /url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>myrole</role-name>
</auth-constraint>
</security-constraint>

<login-config>
<auth-method>BASIC</auth-method>
<realm-name>myrealm</realm-name>
</login-config>

<security-role>
<description>The CFO Users</description>
<role-name>myrole</role-name>
</security-role>

I tried using this:
<cargo.servlet.webxml>${project.basedir}/src/test/resources/local/web.xml</cargo.servlet.webxml>
But it never worked for me.

Any direction here.

Thanks,
Abdul

S. Ali Tokmen

unread,
Nov 26, 2024, 1:28:10 AM11/26/24
to Codehaus Cargo

Hi Krishna

This is an interesting ask indeed.

The configuration you mention is for changing the "base" web.xml file of Tomcat, defining things such as the HTTP response types of different extensions, you can read more on https://stackoverflow.com/questions/5937226/what-is-conf-web-xml-used-for-in-tomcat-as-oppsed-to-the-one-in-web-inf when you want.

For your case, two features could help:

Hoping this helps.

Regards

S. Ali Tokmen
https://ali.tokmen.com/
https://contact.ali.tokmen.com/
Abdul --
Codehaus Cargo - https://codehaus-cargo.github.io/
---
You received this message because you are subscribed to the Google Groups "Codehaus Cargo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codehaus-carg...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/codehaus-cargo/b58b4c3a-ce2c-49e2-aa22-18d87e52de5dn%40googlegroups.com.

Krishna Revuru

unread,
Nov 26, 2024, 2:17:32 PM11/26/24
to Codehaus Cargo
Thanks Ali.
Best Regards.

Krishna Revuru

unread,
Nov 26, 2024, 2:17:32 PM11/26/24
to Codehaus Cargo
Hello Ali,
I did explore the options, but unfortunately they did not work out for me.
I wanted to keep my production code-base in tact, and consolidate all my test setup into src/test/
On the same lines, was trying to see if I could use a <cargo.servlet.webxml> to specify a custom web.xml for a running instance.
Is this an achievable feat?
Thanks & Regards

On Tuesday, November 26, 2024 at 1:28:10 AM UTC-5 goo...@alishomepage.com wrote:

S. Ali Tokmen

unread,
Nov 26, 2024, 4:09:06 PM11/26/24
to codehau...@googlegroups.com

Hi Krishna

Here's the (ugly but working) method:

  • Add a maven-antrun-plugin which:
    1. Extracts over ${project.build.directory}/${project.build.finalName}.war to a folder, say ${project.build.directory}/${project.build.finalName}-itests
    2. Copies over the artifacts you need from src/test into ${project.build.directory}/${project.build.finalName}-itests
  • Set the deployable location in the Codehaus Cargo Maven3 plugin to ${project.build.directory}/${project.build.finalName}-itests

We use a "similar trick" in https://github.com/codehaus-cargo/cargo/blob/master/extensions/maven3/archetypes/multiple-containers/src/main/resources/archetype-resources/pom.xml for example.

Krishna Revuru

unread,
Nov 27, 2024, 5:19:54 PM11/27/24
to Codehaus Cargo
Thanks Ali, will explore that.
Best Regards,
Reply all
Reply to author
Forward
0 new messages