[英]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. 我正在使用
java -classpath $CLASSPATH ...
,其中$CLASSPATH
已设置为/file1path/file1:/file2path/file2
,依此类推。 Despite this, Java complains that file1
is not found. 尽管如此,Java抱怨找不到
file1
。 I tried to set -Dfile1=file:///fullpath/file1
, but it still says it cannot find the file. 我试图设置
-Dfile1=file:///fullpath/file1
,但是它仍然说找不到文件。 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
. 更具体地说,
this.getClass().getClassLoader().getResourceAsStream(configurationFileName)
返回null
。
The file that is not being found is a configuration file (.properties), not a JAR file. 找不到的文件是配置文件(.properties),而不是JAR文件。
You set a classpath
to point to a directory containing something or an archive containing resources. 您将
classpath
设置为指向包含内容的目录或包含资源的档案。 I don't believe you can add a resource directly to the classpath
. 我不相信您可以直接将资源添加到
classpath
。
Try setting your classpath
to /file1path
instead of /file1path/file1
尝试将
classpath
设置为/file1path
而不是/file1path/file1
The classpath should specify the directory where your package hierarchy rooted. 类路径应指定软件包层次结构所在的目录。
package org.djna, file system : C:/myhome/javastuff/org/djna/Myclass.java
包org.djna,文件系统:
C:/myhome/javastuff/org/djna/Myclass.java
classpath is set to c:/myhome/javastuff
classpath设置为
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 /
. 如果您尝试使用
getResourceAsStream()
或类似方法从应用程序中打开文件,则路径的详细信息取决于文件名是否以/
开头。 Read the docs caefully and all will become clear. 仔细阅读文档,一切都会变得清晰。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.