如何将 java 类的目录添加到项目中?

发布于 2024-07-15 23:50:45 字数 396 浏览 3 评论 0原文

我正在开发一个 Java 项目,并希望包含一个充满类的目录。 这些是“JEdit Syntax”类,位于两个包中:

org.syntax.jedit
org.syntax.jedit.tokenmarker

但是,无论我在哪里查看,它都会告诉我“导入整个 jar 文件”。 我的问题是没有 jar 文件,只有一个带有子目录的目录,两个子目录都充满了 *.java 文件,每个文件都包含一个类。

在Netbeans 6.5中,我通过“Jar/Folder”添加了一个库,并且两者都出现在我创建的新库中,但是当我去导入上面列出的两个包时,出现“org.syntax.jedit不存在”的错误(找不到标志)”。

谁能告诉我我做错了什么?

万分感谢。

I have a Java project I'm working on, and wish to include a directory full of classes. These are the "JEdit Syntax" classes, and come within two packages:

org.syntax.jedit
org.syntax.jedit.tokenmarker

However, everywhere I look it tells me to "import the entire jar file". My problem is that there is no jar file, just a directory with a subdirectory, both filled with *.java files, each containing a class.

In Netbeans 6.5 I added a library by "Jar/Folder", and both appear in my new library I created, but when I go to import the two packages listed above, I get the error that "org.syntax.jedit does not exist (cannot find symbol)".

Can anyone show me what I'm doing wrong?

Thanks a ton.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

内心激荡 2024-07-22 23:50:45

听起来您试图将这两个包分别添加到您的类路径中 - 并且级别错误。
如果您指向一个文件夹,则必须指向包层次结构的“根”文件夹 - 即在本例中为“org”的父文件夹
然后从那里它将向下查找包/文件夹层次结构 org/syntax/jedit 以找到您的类。

因此,如果您的文件位于目录“c:\mylib\src\main\java\org\syntax\jedit”中,那么您需要将编译器文件夹指向“c:\mylib\src\main\java”。
然后应该找到所有的类。

It sounds like you have tried to add the two packages to your classpath seperately - and at the wrong level.
If you are pointing at a folder, you have to point to the "root" folder of the package hierarchy - ie in this case the folder which is the parent of "org"
Then from there it will look down the package/folder hierarchy org/syntax/jedit to find your classes.

So if your files are in the directory "c:\mylib\src\main\java\org\syntax\jedit" then you need to point the compiler folder at "c:\mylib\src\main\java".
That should then find all the classes.

小…红帽 2024-07-22 23:50:45

我同意 evnafets 的观点,您可能添加了 org 目录,但您应该添加包含它们的目录。 如果有 ant 文件 (build.xml),您还可以轻松地从这些目录中构建 jar。

I agree with evnafets, you probably added the org directories, but you should have added the directory that contains them. You can also build a jar out of those directories easily if there is an ant file (build.xml).

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