如何在NetBeans中添加JAR [英] How to add a JAR in NetBeans

查看:425
本文介绍了如何在NetBeans中添加JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您创建了一个新项目,并希望它能够使用某些第三方库,比如 widget.jar 。你在哪里添加这个JAR:

Let's say you create a new project, and want it to make use of some 3rd party library, say, widget.jar. Where do you add this JAR:


  1. 文件>>项目属性>>库>> 编译时库 ;或

  2. 文件>>项目属性>>库>> 运行时库;或

  3. 工具>>库(库管理器)>>库类路径;或

  4. 工具>> Java平台(Java平台管理器)

  1. File >> Project Properties >> Libraries >> Compile-Time Libraries; or
  2. File >> Project Properties >> Libraries >> Run-Time Libraries; or
  3. Tools >> Libraries (Library Manager) >> Library Classpath; or
  4. Tools >> Java Platforms (Java Platform Manager)

所有这些对话框似乎做同样的事情,但我相信他们都有适当的用法。无法在线找到好的最佳实践文章,NetBeans帮助内容对话框也没有帮助。

All of these dialogs seem to do the same thing but I'm sure they all have their proper usages. Can't find a good "best practices" article online and the NetBeans Help Contents dialog isn't helping with this either.

推荐答案

您希望将库添加到项目中,这样您就可以自己确定两个选项:

You want to add libraries to your project and in doing so you have two options as you yourself identified:

编译时库是库这是编译应用程序所必需的。当您的应用程序被组装时(例如,进入war文件),它们不包括在内。必须由运行项目的容器提供此类库。

Compile-time libraries are libraries which is needed to compile your application. They are not included when your application is assembled (e.g., into a war-file). Libraries of this kind must be provided by the container running your project.

这在
你想要改变API和实现,或者库是由容器提供的情况下很有用(javax通常就是这种情况) .servlet,需要编译但由应用程序服务器提供,例如Apache Tomcat)。

This is useful in situation when you want to vary API and implementation, or when the library is supplied by the container (which is typically the case with javax.servlet which is required to compile but provided by the application server, e.g., Apache Tomcat).

运行时库是编译和运行项目时都需要的库。在大多数情况下,这可能是您想要的。例如,如果您的项目打包成war / ear,那么这些库将包含在包中。

Run-time libraries are libraries which is needed both for compilation and when running your project. This is probably what you want in most cases. If for instance your project is packaged into a war/ear, then these libraries will be included in the package.

至于其他使用库管理器全局库的其他alernatives em> jdk 库。后者只是您的常规Java库,而前者只是您以通用名称存储一组库的一种方式。对于您以后的所有项目,您只需选择从库管理器中导入库,而不是手动分配库。

As for the other alernatives you have either global libraries using Library Manageror jdk libraries. The latter is simply your regular java libraries, while the former is just a way for your to store a set of libraries under a common name. For all your future projects, instead of manually assigning the libraries you can simply select to import them from your Library Manager.

这篇关于如何在NetBeans中添加JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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