简体   繁体   English

影响是否可以找到类的javac类路径的顺序

[英]order of javac classpath affecting whether classes can be found

I have a jar file, MyClasses.jar , that contains a class MyReader . 我有一个jar文件MyClasses.jar ,其中包含一个类MyReader I have a client class BuildReader which uses it: 我有一个使用它的客户端类BuildReader

// BuildReader.java
MyReader reader = new MyReader();

BuildReader.java is in the current working directory for this example (and is the only file present). BuildReader.java在此示例中位于当前工作目录中(并且是唯一的文件)。 If I compile with: 如果我编译:

javac -cp .:/path/to/MyClasses.jar BuildReader.java 

Then I get an error that javac can't find the class MyReader . 然后我得到一个错误,javac找不到类MyReader

BuildReader.java:24: error: cannot find symbol
MyReader file = new MyReader();
^
symbol:   class MyReader
location: class BuildReader

However, if I compile instead with: 但是,如果我用以下命令编译:

javac -cp /path/to/MyClasses.jar:. BuildReader.java

it compiles just fine. 它编译就好了。 Everything I've looked at online suggest that the only thing that could be a problem is that perhaps there are other versions of MyReader about; 我在网上看到的所有内容都表明,唯一可能出现问题的地方可能是MyReader其他版本。 there aren't. 没有。 Can anyone help me to understand why the order of the javac classpath is causing compiler errors? 谁能帮助我了解为什么javac类路径的顺序导致编译器错误? I am not the creator of MyClasses.jar , if that's relevant. 如果相关,我不是MyClasses.jar的创建者。

您没有说,但是我敢打赌您正在使用Windows,其中的类路径分隔符为';',而不是':'。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM