Java包不存在错误 [英] Java Package Does Not Exist Error

查看:581
本文介绍了Java包不存在错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以在根目录中有一个文件夹 / usr / share / stuff

So there's a folder /usr/share/stuff in the root directory

一堆带有的软件包org.name 顶部的定义

我正在运行 javac test.java 其中 test.java 在子域中

I am running javac test.java where test.java is in a subdomain

我添加了 / usr / share / stuff 到我的班级路径。

I added /usr/share/stuff to my class path.

并在顶部测试.java 我添加 import org.name

但我得到包不存在错误...为什么?

But I get a package does not exist error...why?

推荐答案

他们是否在右边子目录?

Are they in the right subdirectories?

如果在类路径上放置 / usr / share / stuff ,则使用<$ c定义文件$ c> package org.name 应该在 / usr / share / stuff / org / name

If you put /usr/share/stuff on the class path, files defined with package org.name should be in /usr/share/stuff/org/name.

编辑:如果你还不知道这一点,你应该读一读: http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/classpath.html#Understanding

EDIT: If you don't already know this, you should probably read this: http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/classpath.html#Understanding

编辑2 :对不起,我没有意识到你在讨论 / usr / share / stuff 。它们不仅需要位于适当的子目录中,而且还需要编译它们。 .java 文件不需要在类路径上,而是在源路径上。 (生成的 .class 文件需要在类路径上。)

EDIT 2: Sorry, I hadn't realised you were talking of Java source files in /usr/share/stuff. Not only they need to be in the appropriate sub-directory, but you need to compile them. The .java files don't need to be on the classpath, but on the source path. (The generated .class files need to be on the classpath.)

如果编译它们可能会失败它们不在正确的目录结构下,但它们应该是,或者它至少会产生警告。生成的类文件将位于正确的子目录中(如果有,则指定 -d )。

You might get away with compiling them if they're not under the right directory structure, but they should be, or it will generate warnings at least. The generated class files will be in the right subdirectories (wherever you've specified -d if you have).

你应该使用像 javac -sourcepath。:/ usr / share / stuff test.java 之类的东西,假设你已经把 .java / usr / share / stuff / usr / share / stuff / org / name (或根据其包装名称适当的任何东西)。

You should use something like javac -sourcepath .:/usr/share/stuff test.java, assuming you've put the .java files that were under /usr/share/stuff under /usr/share/stuff/org/name (or whatever is appropriate according to their package names).

这篇关于Java包不存在错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆