包不存在?
我的目录结构是:
ABC/src/com/example/model/a.java
ABC/src/com/example/web/b.java
代码 a.java
:
package com.example.model;
public class a {
// ...
}
b.java
的代码:
package com.example.web;
import com.example.model.*;
public class b {
// ...
}
我已经将CLASSPATH
环境变量设置为Tomcat的servlet-api.jar
,所以我不需要将其包含在javac
命令。
现在a.java
编译得很好,但是当我编译b.java
时它说“package com.example.model不存在”。
这是如何引起的以及如何解决?我使用的是 Ubuntu 10.10。
My directory structure is:
ABC/src/com/example/model/a.java
ABC/src/com/example/web/b.java
Code for a.java
:
package com.example.model;
public class a {
// ...
}
Code for b.java
:
package com.example.web;
import com.example.model.*;
public class b {
// ...
}
I have already set the CLASSPATH
environment variable to Tomcat's servlet-api.jar
, so I don't need to include it in the javac
command.
Now a.java
compiles fine but when I compile b.java
it says "package com.example.model does not exist".
How is this caused and how can I solve it? I am using Ubuntu 10.10.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
将输出目录(ABC/classes 或类似目录)添加到 javac 类路径,以便 javac 可以找到这些类。
编辑:
实际上,正如 AlexR 所指出的,首选方法是添加 -sourcepath 选项。
这样,编译器将使用当前的代码源,而不是上次编译时的类文件。
Add the output directory (ABC/classes or similar) to the javac classpath so that javac can find the classes.
Edit:
Actually, the preferred way is to add the -sourcepath option, as pointed out by AlexR.
That way, the compiler will use the current source of your code instead of the class files from the last time you compiled.