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

The Archive Base Latest Questions

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

My test code in Maven project B (which is a child of project A)

  • 0

My test code in Maven project B (which is a child of project A) has something like

String filePath = "src/main/webapp";
//do something with the filePath

The above test case runs fine when I run the project from child (i.e, level B) but when I run from Parent project A (i.e, doing a mvn install at parent level) this fails because obviously there is no folder called “src/main/webapp” under parent level (It is however available in child level).

I know I could do some coding do check if a test case is running from parent/child module but apparently I want to know what others have done when they have had this problem ?

And no, I cant use the classpath instead (for various boring reasons).

I also tried relative path but then the test case sort of starts to know too much. Is there actually a solution at all for this ?

UPDATE (12/Feb) – I have a web.xml under webapp folder and create a jetty server in a test case using that web.xml. Ideally src/main/webapp is not placed in the classpath. It is used by the WAR plugin to package the WAR. Now, I tried an alternative where I put my web.xml in the src/main/resource/console-webapp/WEB-INF/web.xml directory and altered the webXml attribute in the maven war plugin. This seems to solve my problem. However, in the output WAR I have a web.xml and another redundant web.xml (which was copied because it is in the classpath).

I have tried “packageExcludes” and “webResources/excludes” and got the war plugin to omit the second web.xml but still the directory “console-webapp” gets copied (although is empty). Is there any way to tell maven war plugin to ignore a directory completely (i.e, what is the ant pattern for that?)

  • 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-13T18:12:30+00:00Added an answer on May 13, 2026 at 6:12 pm

    The Maven 2 conventions state that all test resources, including files such as the one you are trying to use in your test, must be stored in the src/test/resources folder. If you respect this convention, you will be able to get your file from the classpath directly. These resources will not be included in the final packaging (JAR, WAR, EAR…).

    Of course, you can change the directory and then specify the new test resources directory in your pom.xml:

    <build>
        <testResources>
            <testResource>
                <directory>...</directory>
            </testResource>
        </testResources>
        ...
    

    In your question, you specified that you can’t use the classpath. Why so?

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

Sidebar

Related Questions

I am developing a java project with maven which generates code files. I am
During the test phase of my maven build I ave the following code in
The test code below leads to a null pointer deference bug on a String
My maven reports are working great, all except Checkstyle and test xref. My test
How do I get IntelliJ to auto-configure the Scala facet in a Maven project
Using intellij and maven pom files, how do i debug tests run inside the
I would like to annotate many of my Hibernate entities that contain reference data
The test that fails when tested together with mvn test (or through the ide)
We build software using Hudson and Maven. We have C#, java and last, but
This is in a way a follow-up of a previously unanswered question of mine

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.