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

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

问题描述

假设您创建了一个新项目,并希望它使用某些 3rd 方库,例如 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 平台管理器)

所有这些对话框似乎都在做同样的事情,但我相信它们都有正确的用法.在网上找不到好的最佳实践"文章,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:

编译时库是编译应用程序所需的库.当您的应用程序被组装(例如,到一个战争文件中)时,它们不包括在内.此类库必须由运行项目的容器提供.

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.

至于其他替代方案,您可以使用 Library Managerjdk 库来使用 全局 库.后者只是您的常规 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天全站免登陆