10

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:

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?

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?

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.


UPDATE: Here is a picture of my setup.

Joe
  • 303
  • 1
  • 4
  • 9

2 Answers2

9

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?

First, register the libraries in the IDE.

  1. In the IDE, choose Tools > Libraries to open the Libraries Manager.
  2. Click New Library and 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

alt text
(source: netbeans.org)

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

  1. Select the project from the Project view, right-click and select "Properties"
  2. Under the Libraries category, click on the "Add Library..." button and choose the HTMLUnit library and click OK to complete

alt text
(source: netbeans.org)

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

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

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • I did exactly what you said above and now I do see the HTML Unit jar files under Libraries in the projects tree in netbeans. The problem is, the imports still don't work. The first part of the path: "com" has the read line under it and says "package com.gargoylesoftware.htmlunit does not exist". Any thoughts on whats not working? Also, good detailed answer and thanks for your help. – Joe Jul 18 '10 at 23:16
  • @Joe can you try to rebuild the project – Pascal Thivent Jul 18 '10 at 23:20
  • When I do, I get that same "package com.gargoylesoftware.htmlunit does not exist" error. – Joe Jul 19 '10 at 00:40
  • I added a screenshot of my netbeans project for you to take a look at. Maybe you can see if I am doing something wrong. Thanks – Joe Jul 19 '10 at 01:01
  • 3
    I fixed the problem. In the libraries menu, I was just adding the folder that contained the jar files. I had to remove that and then add all the jars individually. – Joe Jul 19 '10 at 14:43
  • I dont see the Menu "Tool" like you said, I use Eclipse Mars version – suhao399 Sep 25 '16 at 03:38
1

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.

Kimble
  • 7,295
  • 4
  • 54
  • 77