简体   繁体   English

在NetBeans中引用.jar文件

[英]Referencing .jar files in NetBeans

I am trying to use FEST automation software. 我正在尝试使用FEST自动化软件。 I am currently dealing with NetBeans 6.8 because it is what I have to use at work and am unable to upgrade the software at this time because of our system requirements 我目前正在处理NetBeans 6.8,因为它是我在工作中使用的,由于我们的系统要求,目前无法升级软件

[TLDR: don't tell me to upgrade NetBeans because I can't] [TLDR:不要告诉我升级NetBeans,因为我做不到]

I have downloaded the jar files from the google code repository and am trying to get a very simple application to work. 我从谷歌代码库下载了jar文件,并试图让一个非常简单的应用程序工作。 I have tried adding the jar files to Libraries through the property panel for my project. 我已经尝试通过我的项目的属性面板将jar文件添加到库。 NetBeans still cannot find these methods. NetBeans仍然找不到这些方法。 Where else/how do I add these jar files to the class paths? 在哪里/如何将这些jar文件添加到类路径?

In order to use .jar files in NetBeans, you can either add the jar file to your global libraries or your local libraries. 要在NetBeans中使用.jar文件,您可以将jar文件添加到全局库或本地库中。 It sounds like you tried doing it locally without much success. 听起来您尝试在本地进行尝试没有太大的成功。 I recommend adding a library such that you can just pick from your list of libraries without needing to reload it. 我建议添加一个库,以便您可以从库列表中选择而无需重新加载它。 I use NetBeans 8.1 so it may be just a bit different for 6.8. 我使用的是NetBeans 8.1,因此它可能与6.8有所不同。

What you need to do is go to Tools->Library 您需要做的是转到工具 - >库

Then you need to click on New Library at the bottom left of the dialogue box. 然后,您需要单击对话框左下方的“新建库”。

AddLibrary AddLibrary

Name it and hit 'Ok'. 命名并点击“确定”。 Then, you'll add a new jar file by specifying your jar path. 然后,您将通过指定jar路径添加一个新的jar文件。 Hit 'Ok' again to save everything. 再次点击“确定”以保存所有内容。

In order to use your new library, you'll need to then click on your Libraries folder in your project and add a new library. 要使用新库,您需要单击项目中的Libraries文件夹并添加新库。 Select from the list of libraries the library you just created. 从库列表中选择刚刚创建的库。

SelectLibrary SelectLibrary

Finally, you import your individual files in your library using the #import keyword as per usual. 最后,您可以像往常一样使用#import关键字将单个文件导入库中。 If you want to import everything, you'd type something akin to 如果要导入所有内容,请输入类似于

import MyNewLibrary.*;

To load a library the way you tried to do it, you'd right click the libraries folder and click "Add JAR/folder" instead of "Add Library". 要以您尝试的方式加载库,您可以右键单击libraries文件夹并单击“添加JAR /文件夹”而不是“添加库”。 Then you'd import everything. 然后,您将导入所有内容。

If you still for some reason cannot get your library to work, then you probably aren't importing using the right name. 如果由于某种原因仍然无法使您的库工作,那么您可能没有使用正确的名称导入。 Or, you might be trying to load a static library without using the static keyword. 或者,您可能试图在不使用static关键字的情况下加载静态库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM