Kemin Zhou
Kemin Zhou

Reputation: 6891

Properties file could not be found by getResourceAsStream(). Check the CLASSPATH or class loader

This is from an open source project where there is nearly no support. Compilation of the project went well. But I cannot test or install because of a particular property file cannot be found. I have search up and down the internet and not able to find any solutions. The organization of the director is a little bit unconventional.

some directories. core/src/main/java/org/mskcc/cbio/portal/util/Config.java.

String props = "portal.properties";
InputStream in = this.getClass().getClassLoader().getResourceAsStream(props);
...

more directoires. src/main/resources/portal.properties.

This last src directory has only one subdirectory main, and the main directory has only one resources subdirectory. The file that could not be found is located here.

I am using java 1.7. Maven 3.0.5 The command I used is mvn install

I must be missing one simple configuration somewhere.

There got to be some who can resolve this easily.

Upvotes: 3

Views: 3342

Answers (1)

Michael Henrique
Michael Henrique

Reputation: 235

src/main/resources is, by default, the path of Aplication/Library resources in Maven. But, you can optionally force this in the pom.xml.

1) Add in the pom.xml

<resource>
   <directory>src/main/resources</directory>
   <filtering>true</filtering>
</resource>

2) run maven -> mvn clean install

3) Search for portal.properties at the build generated at "target" folder. Assert that portal.properties is in the root of the artifact classpath (root of .jar, .ear or /classes in .war).

Upvotes: 1

Related Questions