I have a testng class which tests a class which in turns load property from classpath.When i run maven install i am getting an error mentioning file not found.It is not able to find the property file though i have it in src/test/resources. How to resolve this issue?
the java code is having a constructor which tries to load the property file Properties props = JobUtils .loadProperties("x.properties"); my maven configuration:
<plugin>
<groupId>org.apache.maven.plugins
<artifactId>maven-surefire-plugin
<version>2.5
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>
with:
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
</testResource>
</testResources>
</build>
Also I have this x.properties in src/test/resource
Stack trace Running TestSuite is:
java.io.FileNotFoundException: x.properties (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:106)
at java.io.FileInputStream.(FileInputStream.java:66)
Also note the test class i have tries to instantiate this java code and test it.
Your
x.propertiesfile from thesrc/test/resourcesdirectory is actually being copied to thetarget/test-classesdirectory after the Mavenprocess-test-resourcesphase is executed. So if you want your application to be able to find it, you should use the following file-path:However I do not think this is exactly what you are looking for. I recommend to read the property file directly from the CLASSPATH (without using the file-system directly) using a code like this:
Using this approach you will be able to load the property file even from within a JAR file distributed to the customer or also from a configuration file that is added to the CLASSPATH in some kind of a launch-script.