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 1019617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:02:30+00:00 2026-05-16T11:02:30+00:00

I am trying to control which files make into the WAR package that is

  • 0

I am trying to control which files make into the WAR package that is created by mvn package goal. Specifically, I want to exclude some files from the default src/main/resources folder for each package (I am trying to do builds/package for different environments).

I tried using maven-war-plugin but failed. If I add this configuration (for testing):

<webResources>
    <resource>
        <directory>src/main/resources</directory>
        <targetPath>WEB-INF/classes</targetPath>
        <excludes>
            <exclude>*.xml</exclude>
        </excludes>
    </resource>
</webResources>

…my WEB-INF/classes will still contain the XML files. This is because webResources parameter seems to duplicate the copying process (the above configuration actually works, an files are not copied… but they get copied in some other process instead).

Maven-war-plugin documentation states:

The default resource directory for all Maven 2 projects is src/main/resources which will end up in target/classes and in WEB-INF/classes in the WAR. The directory structure will be preserved in the process.

The WAR Plugin is also capable of including resources not found in the default resource directory through the webResources parameter.

This is a bit confusing. Does it mean that:

  • The webResources parameter is a feature in maven-war-plugin that allows files to be included only from outside src/main/resources folder? If so, how can we alter the copied files from inside src/main/resources?
  • The webResources parameter is a feature in maven-war-plugin that allows files to be included also from outside src/main/resources folder? If so, how can it be configured to do this?
  • Some other option?
  • 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-16T11:02:30+00:00Added an answer on May 16, 2026 at 11:02 am

    I am trying to control which files make into the WAR package that is created by mvn package goal. Specifically, I want to exclude some files from the default src/main/resources folder for each package

    Resources from the default resource directory (src/main/resources) are copied into the build output directory (target/classes) during the process-resources phase. Then, during the package phase, the content of target/classes is taken and packaged into a distributed archive, like a WAR, and end up in WEB-INF/classes in that case.

    So, if you want to control what resources end up in WEB-INF/classes, you need to control what resources will end up in target/classes i.e to somehow alter the behavior of the goal bound to the process-resources phase, specifically the resources:resources goal of the Maven Resources Plugin.

    And to do so, (this is probably not intuitive), you can declare exclude or include elements inside resources element of the pom, as shown in Including and excluding files and directories. Applied to the default resource directory:

    <build>
      <resources>
        <resource>
          <directory>src/main/resources</directory>
          <excludes>
            <exclude>**/*.xml</exclude>
          </excludes>
        </resource>
      </resources>
    </build>
    

    And if you want to do use custom exclusion rules for different environments, combine this with profiles. For example:

    <project>
      ...
      <profiles>
        <profile>
          <id>env-uat</id>
          <activation>
            <property>
              <name>env</name>
              <value>uat</value>
            </property>
          </activation>
          <build>
            <resources>
              <resource>
                <directory>src/main/resources</directory>
                <excludes>
                  <exclude>**/*.xml</exclude>
                </excludes>
              </resource>
            </resources>
          </build>
        </profile>
      </profiles>
    </project>
    

    And when using this profile, the xml files won’t end up in target/classes and consequently they won’t end up in WEB-INF/classes in the final war.

    I tried using maven-war-plugin but failed. If I add this configuration (for testing) (…) my WEB-INF/classes will still contain the XML files

    What you’re doing here is adding an additional resources directory, which appears to be the already included default resource directory. So, whatever you’ll exclude, this has no effect since the files get copied to target/classes during process-resources anyway and thus still end-up in WEB-INF/classes.

    In other words, use webResources when you want to add extra resources that are not part of the default resource directory:

    <project>
      ...
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1</version>
            <configuration>
              <webResources>
                <resource>
                  <!-- this is relative to the pom.xml directory -->
                  <directory>extra-resources</directory>
                </resource>
              </webResources>
            </configuration>
          </plugin>
        </plugins>
      </build>
      ...
    </project>
    

    But I don’t think that this is what you’re looking for here and suggest using the approach suggested above.

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

Sidebar

Related Questions

I'm trying to create a server control, which inherits from TextBox, that will automatically
I'm trying to create a WPF Shape (PolyLine) editor, which is a control that
A while back I was trying to bruteforce a remote control which sent a
What I'm trying to do is pass parameters to a user control view which
I'm trying to create a custom control - a button - which will have
I'm trying to skin HTML output which I don't have control over. One of
I have an XML feed (which I don't control) and I am trying to
I'm trying to control the main timeline of my flash application from a MovieClip
I am trying to control some LEDs wired to the parallel port on Windows
I'm trying to control the titles of my xterm windows and my cleverness has

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.