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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:07:27+00:00 2026-05-27T19:07:27+00:00

I have a Java project and used the standard maven archetype to create the

  • 0

I have a Java project and used the standard maven archetype to create the dir structure.
It looks like this:

|-src/main/java 
|-src/main/resources
|-target/classes
|- ... 

Now one of my classes uses a .properties file to read in some settings. I placed it in src/main/resources and read it through File propertiesFile = new File("./src/main/resources/starter.properties");.
When I use the eclipse run-configuration, everything works fine. But recently I tried to start the same Java-class from my console using java some.package.Class, and since the .class-file is located in target/classes I got the message, that ./src/main/resources/starter.properties couldn’t be found.

What am I doing wrong? Is the .properties file not supposed to be located in the resources-folder or do I have to use an other way to load it?

  • 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-27T19:07:28+00:00Added an answer on May 27, 2026 at 7:07 pm

    The two previous answers are correct, but I wanted to give a bit more context.

    This file is in two places. It starts off in /src/main/resources and when you build the project, Maven copies it to /target/classes.

    At runtime, you shouldn’t access the copy that is in your source code. Otherwise, your software would need access to the source code in order to run. Rather, you should access the copy that is in your deliverable. At execution time, you can safely assume that you will find it on the classpath. It’s in the same place as your compiled classes, so if it weren’t on the classpath, you wouldn’t have been able to run the program in the first place. This is why you should use getResourceAsStream() as mentioned by the other answerers.

    (Though for production software, I do recommend Spring’s Resource abstraction for accessing these kinds of things.)

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

Sidebar

Related Questions

I have a large CVS Repository in a Netbeans Java Project. I used to
I have Java project that I formerly debugged using Sysdeo Launcher. Now I'd like
I have a Java Spring project, configured with Maven. As the amount of unit
I have a Java project that builds using Apache Ant to a website. This
I have Java project built with Maven2. There is used JUnit framework for testing
I have a Java project that needs a addon interface. I was thinking about
I have a Java project in Eclipse with ~10 packages and ~10 class files
I have a Java project connecting to an Ingres database and using the Spring
I have a Java project that I'm trying to implement with a model-view-controller design.
I have a Java project with a toolbar, and the toolbar has icons on

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.