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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:48:00+00:00 2026-06-09T20:48:00+00:00

I have an Eclipse project with the following directory structure: MyProj/ src/main/java/ com.me.myproject.widgets Widget.java

  • 0

I have an Eclipse project with the following directory structure:

MyProj/
    src/main/java/
        com.me.myproject.widgets
            Widget.java
    src/main/config
        widget-config.xml
    src/test/java
        com.me.myproject.widgets
            WidgetTest.java
    src/test/config
        widget-test-config.xml

The Widget class reads its config (XML) file in from anywhere on the classpath and uses it to configure its properties.

I am trying to just get WidgetTest‘s test cases (all written with JUnit) to run inside Eclipse when I right-click the file and go to Run As >> JUnit Test. I assume I’ll have to actually run it as a customized Run Configuration with its own configured classpath, but I’m not sure about that as I’ve never done this before.

Does anybody know how I can get a custom Run Configuration to run WidgetTest.java as a JUnit test, and successfully place src/test/config/widget-test-config.xml on the classpath? Thanks in advance!

Please note, this question is not about how to read a resource from the runtime classpath, its about how to get it on Eclipse’s JUnit Run Config classpath in the first place!

  • 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-06-09T20:48:02+00:00Added an answer on June 9, 2026 at 8:48 pm

    I was under the impression that as long as you have src/test/config/widget-test-config.xml inside what Eclipse considers to be a source folder, it should already be on the classpath.

    Is src/test a source folder for Eclipse ? If it is and you still get the problem, try out the following experiment :

    If you copy widget-test-config.xml to the src root can Widget class read it ?

    If Yes

    then it’s a problem of the test folder not being on the classpath and you may wanna try adding it manually like so.

    Right click WidgetTest and select Run As -> Junit Test. This should automatically create a Junit Run Configuration accessible at Run -> Run Configurations. You modify it’s Classpath entry to add the project containing the .xml file like so :

    enter image description here

    If No

    If, even after moving the .xml file to the src root (i.e. default package), your widget class cannot read it then there is something else wrong. In that case, it would be great if you could furnish the snippet of code in WidgetTest which is trying to read the .xml file.

    Working Code

    Here is a bit of working code :

    public class A {
    
        @Test
        public void test() {
            InputStream stream = A.class.getResourceAsStream("/SomeTextFile.txt");
            System.out.println(stream != null);
            stream = Test.class.getClassLoader()
                .getResourceAsStream("SomeTextFile.txt");
            System.out.println(stream != null);
        }
    
    }
    

    The above works for me in a simple JAVA project and runs fine. (Running fine means getting
    ‘true’ printed on the console)

    I am in the process of creating a GITHub repo for you to try out this code painlessly.

    GIT Hub Repo with Test project

    You should be able to import the project in this zip and see the code working. Right click on the Test class A and click Run As -> Junit Test, and you should see two true in the Console.

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

Sidebar

Related Questions

I have an Eclipse project with the following directory structure: MyProj >> src/main/java >>
I have the following directory structure of a project: Folder project in Eclipse: --folder
I have the following setup: eclipse a standard Java project (A) an eclipse plugin
I have a simple java project with this basic structure: IncludeMe src deploy siteSpecific
I have the following package on Eclipse: com.mortgageapp.projects.app I'm not interested about the package
Eclipse project, I have Subversion set to ignore the bin directory, and also within
I have created a simple project in java using eclipse ide to test the
I have the following setup: I have an eclipse project which uses generated sourced
I have created a Java project in Eclipse and successfully executed it directly from
Here is my scenario: I have an Eclipse project in my desktop in 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.