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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:34:27+00:00 2026-05-20T21:34:27+00:00

I have a project that uses the normal Maven structure, e.g. module \ src

  • 0

I have a project that uses the normal Maven structure, e.g.

module
\ src
  \ main
    - java
    - resources
  \ test
    - java
    - resources

etc. Under test/resources, I’d like to keep a set of test input files for a parser I’m writing, then run all files in the directory through the test suite. As written now, the test code works from the command line, but fails when run through the Eclipse JUnit plugin:

File file = new File("src/test/resources");
file.list();

(I’m actually using a FilenameFilter, but I’m trying to simplify.)

The problem, after poking through the unit test with a debugger, turns out to be that the File I’m constructing points to /path/to/workspace/myproj/src/test/resources, whereas the actual files reside in /path/to/workspace/myproj/modulename/src/test/resources (it’s a Maven multi-module project). Apparently, this isn’t a problem when running mvn test from the command line.

I guess my question is two-fold: one, am I doing this wrong? I see a lot of people using the class loader to discover resources, as in this question, but I don’t want all the resources of a particular type, just one directory under test/resources. Two, if this isn’t a terrible idea in the first place, do I have a configuration error (e.g. it “should” work)? Is it Eclipse’s fault, a Maven problem, or what?

  • 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-20T21:34:28+00:00Added an answer on May 20, 2026 at 9:34 pm

    One trick would be to place a file in resources with a known name, get the URI of this file through the classloader, then construct a File from this URI, then get the parent, and list() the contents of that directory. Kind of a hack, but it should work.

    So here’s what the code should look like, but place a file called MY_TEST_FILE (or whatever) in test/src/resources

    URL myTestURL = ClassLoader.getSystemResource("MY_TEST_FILE");
    File myFile = new File(myTestURL.toURI());
    File myTestDir = myFile.getParentFile();
    

    Then you have access to the directory you’re looking for.

    That said, I’d be surprised if there’s not a more ‘maven-y’ way to do it..

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

Sidebar

Related Questions

I have a project that uses the maven-assembly-plugin to create source and binary tar
I have Midas project that uses a TDataSetProvider in one of RemoteDataModules in the
I have inherited a project that uses LLBLGen Pro for the DB layer. The
I have inherited a project that uses the following pattern for passing parameters from
We have an old project that requires occasional maintenance that uses VS2003 and Dot
I have a .net interop project that uses an app.config file. When I am
I have a native VC++ project that uses a dll (which is not in
I have a .NET 3.5 WinForms project that uses several 3rd party controls and
I have an existing asp.net webforms project that uses Microsoft's Enterprise DAAB for the
I am working on a large project that uses the STL and have a

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.