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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:05:02+00:00 2026-05-15T07:05:02+00:00

I have a simple java maven project. One of my classes when executing needs

  • 0

I have a simple java maven project. One of my classes when executing needs to load an xml configuration file from the classpath. I don’t want to package such xml file when producing the jar but I want to include a default xml file in a zip assembly under a conf subfolder and I also want this default xml to be available in the unit tests to test against it.

As I see it there are 2 possible places of this default xml:

  1. src/main/resources/conf/default.xml
  2. src/main/conf/default.xml

Both solutions demand special pom actions:

  • In solution 1, I get the auto copy to target folder during build which means it is available in testing but I also get it in the produced jar which i don’t want.

  • In solution 2, I get the jar as I want it(free of the xml) but I manually have to copy the xml to the target folder to be available for testing. (I don’t want to add src’s subfolders in test classpath. I think it is bad practice).

Question: what is the best solution of the two?
– If the correct is 2, what is the best way to copy it to target folder?
– Is there any other solution better and more common than those two?

(I also read Where should I put application configuration files for a Maven project? but I would like to know the most “correct solution” from the “convention over configuration” point of view and this link provides some configuration type solutions but not any convention oriented. Maybe there isn’t one but I ask anyway. Also the solutions provided include AntRun plugin and appAssembler plugin and I wonder if I could do it with out them.)

  • 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-15T07:05:03+00:00Added an answer on May 15, 2026 at 7:05 am

    The question is what is the best solution of the two? If the correct is 2, what is the best way to copy it to target folder? Is there any other solution better and more common than those two?

    Since you want that file to be copied to the target/classes folder, it has somehow to be considered as a resource (so either put in under src/main/resources or declare src/main/conf as resource directory). And if you don’t want it in the final jar, configure the Maven JAR Plugin to exclude it:

    <project>
      ...
      <build>
        <plugins>
          ...
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
              <excludes>
                <exclude>**/conf/*</exclude>
              </excludes>
            </configuration>
          </plugin>
          ...
        </plugins>
      </build>
      ...
    </project>
    

    For the assembly part, assembly descriptors are pretty flexible so it should be possible to achieve what you want regardless of the choice. I’d suggest using the easiest setup though.

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

Sidebar

Related Questions

I have a fairly simple maven-ized Java project, but am having trouble getting my
I have a simple java project (adapted from the example here ), which is
I have written two simple Java classes (one of them containing main(), and the
I have a maven library project with some classes to deal xml messages. Whenever
I am trying to build a simple Java project with Maven. In my pom-file
I have a pretty simple directory layout for my Maven/Eclipse project: . ├── pom.xml
I have Simple java program named MainController.java. Wehn I try to compile it from
I have a simple java code that reads text csv file that contains sentences
I have a java maven project , i installed scala plugin for eclipse and
I have the same problem as Junit4 and TestNG in one project with Maven

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.