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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:18:40+00:00 2026-05-22T20:18:40+00:00

here is the structure of my project. proj —src —-main —-java —-Main.java —-resources —-res.txt

  • 0

here is the structure of my project.

proj
  ---src
    ----main
        ----java
            ----Main.java
        ----resources
             ----res.txt

I am using m2eclipse plugin with Eclipse.
In Main.java, I have

File f = new File("res.txt");  System.out.println(f.getAbsolutePath());

When I run mvn exec:java, the path got printed out is “…\proj\res.txt”. How can I make it look for the resource file in “…\proj\target\classes” directory?

EDIT:

Thanks for the answers to my original question. I have a follow-up questions:

So basically what I want to do is to have the Main class read the “res.txt” and then generate a new “newres.txt” to the resources directory so that I can package this new “newres.txt” to the jar file in the package phase later. Currently I mounted this exec:java to the prepare-package phase. How should I create this “newres.txt” in the resources directory without a hard-coded absolute path or depending on the directory structure of Maven?

  • 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-22T20:18:41+00:00Added an answer on May 22, 2026 at 8:18 pm

    I guess I will answer my own question, Thread.currentThread().getContextClassLoader().getResourceAsStream()
    works the best for me, especially when the project produces a jar dependency for another web project.

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

Sidebar

Related Questions

This is the directory structure of the project (maven2 is used): pom.xml /src /main
Hi I am trying to create a multi-modules project in eclipse with m2eclipse. I
Does any expert here have any particular preference for a JSF 2's project structure.
I have a directory structure like so: project lib paperboy redis-client node-cookie srv main.js
Let's suppose I have the following structure in my project (I'm using iBatis as
Here is my situation. My solution structure is as follows. Project Used to handle
last time I asked how to populate a data structure here . Now I
here is my directory structure. /user/a /user/b /user/b inside folder a,b,c there is a
Here I have: Public Structure MyStruct Public Name as String Public Content as String
Here's my problem.I have 2 xmlfiles with identical structure, with the second xml containing

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.