Java:如何设置 htmlunit

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3277544/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:06:55  来源:igfitidea点击:

Java: how to setup htmlunit

javahtmlunit

提问by Joe

I'm a pretty big noob to Java, but I would like try out htmlunit. I'm using netbeans as my IDE and I've created a project folder "hu1". Here is the structure for that folder:

我是 Java 的大菜鸟,但我想尝试一下 htmlunit。我使用 netbeans 作为我的 IDE,并创建了一个项目文件夹“hu1”。这是该文件夹的结构:

hu1
 > nbproject
 > src 
   > hu1
 > test

Now, I download htmlunit 2.7 and unzipped the folder, which contains a "lib" folder with a bunch of jar files in it. Where do I put that lib folder in my netbeans project folder so that I can use htmlunit?

现在,我下载 htmlunit 2.7 并解压缩文件夹,其中包含一个“lib”文件夹,其中包含一堆 jar 文件。我应该把那个 lib 文件夹放在我的 netbeans 项目文件夹中的什么地方,以便我可以使用 htmlunit?

Also, once I have figured that out, what paths do I use for my imports. A lot of examples I've seen on the web use something like this:

此外,一旦我弄清楚了,我将使用哪些路径进行导入。我在网上看到的很多例子都是这样的:

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.Page;

Where do the the com.gargoylesoftware come from?

com.gargoyle 软件从何而来?

I know this is a beginner questions, and I really should just read up on how to program with java more, but I would appreciate some advice from the experts here.

我知道这是一个初学者的问题,我真的应该多读一下如何用 java 编程,但我会很感激这里专家的一些建议。



UPDATE: Here is a picture of my setup.

更新:这是我的设置图片。

采纳答案by Pascal Thivent

Now, I download htmlunit 2.7 and unzipped the folder, which contains a "lib" folder with a bunch of jar files in it. Where do I put that lib folder in my netbeans project folder so that I can use htmlunit?

现在,我下载 htmlunit 2.7 并解压缩文件夹,其中包含一个“lib”文件夹,其中包含一堆 jar 文件。我应该把那个 lib 文件夹放在我的 netbeans 项目文件夹中的什么地方,以便我可以使用 htmlunit?

First, register the libraries in the IDE.

首先,在 IDE 中注册库。

  1. In the IDE, choose Tools > Librariesto open the Libraries Manager.
  2. Click New Libraryand provide a name for the library, e.g. "HTMLUnit"
  3. With the "HTMLUnit" library selected, click on the "Add JAR/Folder..." button and select the jar file that was downloaded earlier and click OK to complete
  1. 在 IDE 中,选择“工具”>“库”以打开“库管理器”。
  2. 单击新建库并提供的名称,例如“HTMLUnit”
  3. 选择“HTMLUnit”库后,点击“Add JAR/Folder...”按钮,选择之前下载的jar文件,点击OK完成

alt text
(source: netbeans.org)

替代文字
(来源:netbeans.org

Then, add the libraries to the project you are working on.

然后,将库添加到您正在处理的项目中。

  1. Select the project from the Project view, right-clickand select "Properties"
  2. Under the Libraries category, click on the "Add Library..." button and choose the HTMLUnit library and click OK to complete
  1. 从项目视图中选择项目,右键单击并选择“属性
  2. 在库类别下,单击“添加库...”按钮并选择 HTMLUnit 库,然后单击确定完成

alt text
(source: netbeans.org)

替代文字
(来源:netbeans.org

(...) Where do the the com.gargoylesoftware come from?

(...) com.gargoyle 软件从何而来?

From the library you have to add (more precisely, from the htmlunit jars).

从您必须添加的库中(更准确地说,来自 htmlunit jars)。

回答by Kimble

com.gargoylesoftware.htmlunit

com.gargoylesoftware.htmlunit

Is a package in one of the jar files you've downloaded. You have to make sure that these jar files are on the "classpath" in order for Java to find the classes inside (Page, BrowserVersion++). If you're using Netbeans dumping the jar's in the lib folder will usually do the trick.

是您下载的其中一个 jar 文件中的一个包。您必须确保这些 jar 文件位于“类路径”中,以便 Java 找到其中的类(Page、BrowserVersion++)。如果您使用 Netbeans,将 jar 转储到 lib 文件夹中通常可以解决问题。