Anonymous
Anonymous

Reputation: 3404

Why does the Java compiler say my file was not found in the class path when I can clearly see it in the class path?

I am using java -classpath $CLASSPATH ..., where $CLASSPATH has been set to /file1path/file1:/file2path/file2 and so on. Despite this, Java complains that file1 is not found. I tried to set -Dfile1=file:///fullpath/file1, but it still says it cannot find the file. Is there any reason why this might happen other than that I am not seeing a simpler problem like a typo or something (which I have checked for many times)?

More specifically, this.getClass().getClassLoader().getResourceAsStream(configurationFileName) is returning null.

The file that is not being found is a configuration file (.properties), not a JAR file.

Upvotes: 0

Views: 411

Answers (2)

djna
djna

Reputation: 55897

The classpath should specify the directory where your package hierarchy rooted.

package org.djna, file system : C:/myhome/javastuff/org/djna/Myclass.java

classpath is set to c:/myhome/javastuff

If you are trying to open files from your application using getResourceAsStream() or some such the the details of the path depend on whether or not the filename has a leading /. Read the docs caefully and all will become clear.

Upvotes: 3

Vadim
Vadim

Reputation: 5126

You set a classpath to point to a directory containing something or an archive containing resources. I don't believe you can add a resource directly to the classpath.

Try setting your classpath to /file1path instead of /file1path/file1

Upvotes: 3

Related Questions