如何将一组 .java 文件转换为一个工作项目

发布于 2024-08-12 17:18:14 字数 300 浏览 1 评论 0原文

我是一个疯狂的 Java 初学者,仅供参考。

我想编译一个使用这些文件中的 org.json 包的程序(实际上是为了回答一个 SO 问题): http://json.org/java/

我在 NetBeans 中创建了一个基本的 Java 应用程序,但是我该如何做让这些成为我的主类可以识别的类文件,并且它们可以相互识别。我是否需要以某种方式将它们打包并将它们放入项目的类路径中?我可以将它们与主类一起放入我的 src 文件中吗?

I am a crazy Java beginner, FYI.

I want to compile a program (actually to answer an SO question) that uses the org.json package in these files:
http://json.org/java/

I created a basic Java application in NetBeans, but how do I get these to be class files that my main class recognizes, and that they recognize each other. Do I need to jar them somehow and put them in the project's classpath? Can I just slap them in my src file along with the main class?

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

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

发布评论

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

评论(2

云雾 2024-08-19 17:18:14

您可以使用它们创建一个 jar 并将其添加到类路径中。

您也可以将它们放在 src 文件夹中,但需要遵守目录结构。这意味着文件应放置在如下文件夹中:

src/org/json/

You can create a jar with them and add it to the classpath.

You can also put them in the src folder, but you need to honour the directory structure. This means that the files should be placed in a folder like this:

src/org/json/
不爱素颜 2024-08-19 17:18:14

如果您不打算分叉和修改 org.json 包,最好将其用作 jar。使用 netbeans 将其添加到类路径的最简单方法:

  1. 将 jar 下载到项目外部的目录中。
  2. 工具>图书馆>新库...
  3. 正确填写条目,添加 javadoc 和源(如果有)。
  4. 右键单击您的项目并转到属性项。
  5. 图书馆>添加库...
  6. 从列表中选择库。

If you don't plan of forking and modifying the org.json package, it is better to use it as a jar. The easiest way to add it to the classpath with netbeans:

  1. Download the jar in a dir outside the project.
  2. Tools > Libraries > New library...
  3. Fill the entries correctly, add the javadoc and the source if you have it.
  4. Right-click on your project and go to the properties item.
  5. Library > Add library...
  6. Choose the lib from the list.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文