包不存在?

发布于 12-13 14:28 字数 647 浏览 3 评论 0原文

我的目录结构是:

  • 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风吹雨成花2024-12-20 14:28:46

将输出目录(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.

难如初2024-12-20 14:28:46

我猜你忘记添加 -sourcepath 选项。你的编译器不知道你的源代码在哪里,所以它找不到之前编译的a.class。如果添加此选项,您甚至可以只编译 b.java,而 a.java 将自动编译。

BTW 根据 java 命名约定,类名以大写字母开头

I guess you forget to add -sourcepath option. Your compiler does not know where your source is, so it cannot find the a.class previously compiled. If you add this option you even could compile b.java only and a.java will be compiled automatically.

BTW according to java naming convention classes names start with capital letter

最美不过初阳2024-12-20 14:28:46

将 ABC/src 添加到您的类路径并尝试

Add ABC/src to you classpath and try

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文