Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 501943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:14:29+00:00 2026-05-13T06:14:29+00:00

Scenario is such: I have a webapp that I’d like to run dynamically with

  • 0

Scenario is such: I have a webapp that I’d like to run dynamically with the tomcat-maven-plugin’s tomcat:run goal. The wrinkle is that I have numerous classpath resources that need to differ between the packaged artifact and the one run off a local workstation.

Failed Attempts:

1.) My first attempt was to use the builder-helper-maven-plugin, but it won’t work because the target configuration files will (inconsistently!) work their way into the packaged WAR archive.

<plugin>    
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>build-helper-maven-plugin</artifactId>
 <version>1.3</version>
 <executions>

  <execution>     
   <id>add-resource</id>
   <phase>generate-resources</phase>
   <goals>
    <goal>add-resource</goal>
   </goals>
   <configuration>
    <resources>
     <resource>
      <directory>${basedir}/src/main/resources-env/${testEnv}</directory>
      <targetPath>${basedir}/target/classes</targetPath>
     </resource>
    </resources>
   </configuration>
  </execution>
 </executions>
</plugin>

2.) My second attempt was to add the folder (since the files-to-be-deployed aren’t present in Tomcat’s classpath yet either) to -Djava.ext.dirs, but it has no effect (I actually suspect that this systemProperties element is misconfigured or otherwise not working at all). See:

<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>tomcat-maven-plugin</artifactId>
 <version>1.0-beta-1</version>
 <configuration>
  <tomcatWebXml>${basedir}/src/main/mock/web.xml</tomcatWebXml>

  <systemProperties>
   <property>
    <name>java.ext.dirs</name>
    <value>${basedir}/src/main/resources-env/${testEnv}</value>
   </property>      
  </systemProperties>      
  <path>/licensing</path>
 </configuration>
</plugin>

I’m not sure what to attempt next. The heart of the problem seems to be that missing in this plugin is something like Surefire’s <additionalClasspathElement> element.

Would the next step be to create a custom catalina.properties and add it to a <configurationDir>? If so, what would catalina.properties need to look like?

Edit: More thorough explanation follows

I understand this question reads somewhat vaguely, so I’ll try to elaborate a bit.

My POM uses the webResources functionality of the WAR plugin to copy some environment-specific config files and without using a profile to do it, by copying in a resource named /src/main/resources-env/${env} like so:

...
<plugin>    
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
        ...
    <configuration>
            ...
        <webResources>
            <!-- Copy Environment-specific resources to classes -->
            <resource>
                <directory>${basedir}/src/main/resources-env/${env}</directory>
                <targetPath>WEB-INF/classes</targetPath>
            </resource>
        </webResources>
    </configuration>
</plugin>

This will copy the (default, DEV) environment resources into the package and currently works fine. Note also that b/c these occur as part of packaging, the tomcat:run goal is never privy to them (which is desired, as the environments differ).

So the problem is this: when the dynamic tomcat:run is executed, the application will fail because its classpath (it looks at target/classes) will lack the needed local workstation environmental config files. All I need to do is get those on the path for tomcat, but would like to do so without adding anything to the command line and definitely without breaking the build’s integrity if someone follows up with a mvn package and doesn’t clean first.

I hope this is more clear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:14:29+00:00Added an answer on May 13, 2026 at 6:14 am

    I may be missing something but why don’t you declare the required dependencies in a profile and use this profile when running Tomcat? I don’t get why you would need to put these resources at Tomcat’s classpath level.

    UPDATE: I’m editing my answer to cover the comment from the OP itself answering my question above.

    You’re correct, the files really need to be in the webapp classpath, not tomcat’s. So how could I make a profile that activate automatically for tomcat:run but without additional cmd line args?

    I don’t know how to do this without declaring the profile as <activeByDefault> or listing it under the <activeProfiles> (but this is not what I had in mind, I would rather use property activation and call something like mvn tomcat:run -Denv=test, not sure to understand why this is a problem).

    And how should I “declare the dependencies” in the profile while ensuring that subsequent invocations never let them into the package WAR via a vanilla mvn package

    If the previously mentioned profile is active by default, then you’ll need to exclude it if you don’t want it, by calling something like mvn package -P !profile-1. A profile can’t be magically deactivated for one particular goal (at least, not to my knowledge).

    Actually, my understanding is that you really have two different context here: the “testing” context (where you want to include more things in the WAR) and the “normal” context (where you don’t want these things to be included). To be honest, I don’t know how you could distinguish these two situations without specifying any additional parameter (either to activate a profile or to deactivate it depending on the context). You must have valid reasons but, as I said, I don’t really understand why this is a problem. So maybe profiles are not a solution for your situation. But I’d really like to understand why because this seems to be a typical use case for profiles 🙂

    UPDATE2: Having read your comment to the other answer and your update, I realize that my initial understanding was wrong (I though you were talking about dependencies in the maven sense). But, I still think that profiles could help you, for example to customize the <resources> as in this blog post (this is just one way to do, using a property like src/main/resources/${env} in the path is another way to go). But this won’t solve all your concerns (like not specifying additional command line params or automagically cleaning the target directory). I don’t have any solutions for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My scenario is such that I have a VB.NET project in SVN and I
This is the scenario i have: im developing a web app that will list
I'm using SpecFlow, and I'd like to write a scenario such as the following:
I have kind of a such scenario: (source: microsoft.com ) Here i need to
I have such a scenario for our installer project using WIX 3.6: we want
I have a scenario as follows: I have one Windows 2003 server that has
Scenario I have a Node.JS service (written using ExpressJS ) that accepts image uploads
Please consider such scenerio: I have component called TMenuItemSelector which has two published properties:
Another stupid question here regarding a SQL scenario. Given data such as: FieldKey DocumentKey
Scenario While using the Maven Ant Task artifact:deploy , I'm encountering the error java.lang.OutOfMemoryError:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.