java 在 netbeans 中添加其他项目作为库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10315597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
add other projects as library in netbeans
提问by Mohammad Reza Kargar
I have a project A (for example an Ant based Java Application project) and a second project B (a Java Class Library project or another Java Application project, both Ant build based.)
我有一个项目 A(例如一个基于 Ant 的 Java 应用程序项目)和第二个项目 B(一个 Java 类库项目或另一个 Java 应用程序项目,都是基于 Ant 构建的。)
Project B has some additional Java library dependencies (.jar files in the Libraries folder).
项目 B 有一些额外的 Java 库依赖项(Libraries 文件夹中的 .jar 文件)。
A depends on B. A can use classes which are written by myself in B but it can not see classes in the additional libraries of B unless I add those libraries/jar files to A.
A 依赖于 B。 A 可以使用自己在 B 中编写的类,但除非我将这些库/jar 文件添加到 A,否则它看不到 B 的附加库中的类。
Is there a way to get NetBeans to automatically manage the library dependencies in A by including the dependencies of B in addition to B's own jar file? In eclipse when you add .jar files to project B, it is not necessary to add them to A again.
除了 B 自己的 jar 文件之外,有没有办法让 NetBeans 通过包含 B 的依赖项来自动管理 A 中的库依赖项?在eclipse中,当你将.jar文件添加到项目B中时,不需要再次将它们添加到A中。
Thanks.
谢谢。
回答by Steve Pitchers
In your project folder you should see a folder called Dependencies
, right click on that folder and choose Add Dependency...
. Open the Open Projects
tab; from there you can select your project from the list. Click Add
.
在您的项目文件夹中,您应该看到一个名为 的文件夹Dependencies
,右键单击该文件夹并选择Add Dependency...
. 打开Open Projects
标签;从那里您可以从列表中选择您的项目。单击Add
。
This works for NetBeans IDE 7.2.1.
这适用于 NetBeans IDE 7.2.1。
回答by jla
The simpler NetBeans Ant project Libraries folder is used for compile time and run time dependencies of each individual project. If your "Java Class Library" type Ant based project B has additional library dependencies, they are not automatically forwarded or updated in Project A when you include B as a library of A.
更简单的 NetBeans Ant 项目库文件夹用于每个单独项目的编译时和运行时依赖项。如果您的“Java 类库”类型基于 Ant 的项目 B 具有额外的库依赖项,则当您将 B 作为 A 的库包含时,它们不会在项目 A 中自动转发或更新。
When project A is built, it's .jar file will only contain Project A code and the lib/ folder will only include .jar files from it's Libraries folder. This can cause confusion when you upgrade the dependent library versions and possibly forget to upgrade them everywhere you depend on project B.
构建项目 A 时,它的 .jar 文件将仅包含项目 A 代码,而 lib/ 文件夹将仅包含其库文件夹中的 .jar 文件。这可能会在您升级依赖库版本时引起混淆,并且可能忘记在依赖项目 B 的任何地方升级它们。
You will need to manually manage the dependencies unless you switch to a project management and build system that handles this, like Maven.
您将需要手动管理依赖项,除非您切换到处理此问题的项目管理和构建系统,例如 Maven。
A NetBeans Maven project will have a Dependencies folder instead of a Libraries folder and if project B is properly setup and registered as a Maven project and project A is also created as a Maven project, you could Add Dependency on B to A and B would forward it's dependency information to Maven project A.
NetBeans Maven 项目将有一个 Dependencies 文件夹而不是 Libraries 文件夹,如果项目 B 已正确设置并注册为 Maven 项目,并且项目 A 也创建为 Maven 项目,则您可以将 B 上的依赖项添加到 A 并且 B 将转发它是 Maven 项目 A 的依赖信息。
回答by ChadNC
If you want to add another project as a library in netbeans right click on the libraries directory and select "Add Project", select the project you want to add. When you do this the jar file(in the dist dir) that has been built for the project you are adding will be selected and then click the "Add Project jar files" and that should add the jar file to your project. Alternatively you could select "Add Jar" instead and add the jar file yourself the way that Ravi described.
如果要在netbeans中添加另一个项目作为库,在libraries目录上右键,选择“添加项目”,选择要添加的项目。执行此操作时,将为您添加的项目构建的 jar 文件(在 dist 目录中)将被选中,然后单击“添加项目 jar 文件”,这会将 jar 文件添加到您的项目中。或者,您可以选择“添加 Jar”,然后按照 Ravi 描述的方式自行添加 jar 文件。
回答by Ravi Jain
In your project folder you see a folder called Libraries
, right click on that folder from there you can select your .jar
file. You need not to add .jar
files repeatedly after adding once to your project. You just need to Clean and Build
your project whenever new files are added to .jar
file.
在您的项目文件夹中,您会看到一个名为 的文件夹Libraries
,右键单击该文件夹,您可以选择您的.jar
文件。.jar
在项目中添加一次后,您无需重复添加文件。Clean and Build
每当新文件添加到.jar
文件时,您只需要添加到您的项目中。