简体   繁体   中英

order of javac classpath affecting whether classes can be found

I have a jar file, MyClasses.jar , that contains a class MyReader . I have a client class BuildReader which uses it:

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

BuildReader.java is in the current working directory for this example (and is the only file present). 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 .

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; there aren't. Can anyone help me to understand why the order of the javac classpath is causing compiler errors? I am not the creator of MyClasses.jar , if that's relevant.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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