Reputation: 177
In the main()
class i put a code:
App.getClass().getClassLoader().getResourceAsStream("Repo-Offer.properties")
the result is null
The property file resides in:
Project/src/main/resources/properties/Repo-Offer.properties
I was trying to load properties like this:
private Properties getPropertiesFromClasspath(String propFileName) throws IOException {
// loading xmlProfileGen.properties from the classpath
Properties props = new Properties();
InputStream inputStream = this.getClass().getClassLoader()
.getResourceAsStream(propFileName);
if (inputStream == null) {
throw new FileNotFoundException("property file '" + propFileName
+ "' not found in the classpath");
}
props.load(inputStream);
return props;
}
but because of that null it says
Exception in thread "main" java.io.FileNotFoundException: Repo-Offer.properties
How to use the properties files from: Project/src/main/resources/properties/Repo-Offer.properties while the source is in
Project/src/main/java/com/...
? EDIT It is Maven project.
Upvotes: 0
Views: 1656
Reputation: 5279
Assuming you are using Maven, the properties file will land in /properties/Repo-Offer.properties
, so use that as file path.
Have a look in target/classes
to verify the proper path.
Upvotes: 2