This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes properties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark " properties" Watch " properties" New topic
Author properties

Kevin Mayer

Joined: Jan 28, 2009
Posts: 7
1.We have a java application that is functioning correctly.

It uses the following code to load properties from a file.

private final static String PROPS_FILE = "properties/its/LoadDB.props";


public void readDbPropertiesFile(String logPropsFile)
throws FileNotFoundException, IOException {
java.util.Properties props = new Properties();
props.load(new FileInputStream(logPropsFile));

2. When using the junit task in ant, it throws a FileNotFoundException saying. properties/its/LoadDB.props (No such file or directory)

3. The junit classpath in the build.xml is set as follows:
<path id="junit.classpath">
<pathelement location="${build.dir}/release/"/>

4. ${build.dir}/release/" is where the compiled code and properties files are located

Can a second pair of eyes locate why the LoadDB.props cannot be found when running junit?

thank you

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33134

This seems like more of an Ant question than a JUnit one. Moving to our build tools forum.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Peter Johnson

Joined: May 14, 2008
Posts: 5852

Kevin, welcome to Java Ranch!

It looks to me like you are not loading the properties file via the classpath, but rather by using a relative file path. Thus the location you gave is used relative to the current working directory.

To load it via the classpath, use something like:

URL url = this.getClass().getClassLoader().findResource(PROPS_FILE);
props.load(new FileInputStream(url.toString()));

JBoss In Action
Kevin Mayer

Joined: Jan 28, 2009
Posts: 7
Thanks Peter for the insight as to using this.getClass().getClassLoader().findResource(PROPS_FILE). I found one other tidbit that might help someone if they are using the relative path. In the junit ant task, they can specify the directory where they want the jvm to execute from. You do this specifying fork='yes' and dir=. The dir is where the jvm will execute from.

<junit printsummary='yes' fork='yes' dir='${build.dir}/release' haltonfailure='yes' haltonerror='yes'>

For more information see

It's nice to be welcomed here at the Java Ranch.
I agree. Here's the link:
subject: properties
It's not a secret anymore!