user3751508
user3751508

Reputation: 63

Import custom lib Java

Trying to import the "custom" library "Htmlunit" in my project. I use the IDE Netbeans and have done the following:

  1. Right click "Library"
  2. Clicked "Add Library"
  3. Created the Library and added it

I then want to import the jar "htmlunit-2.15" but Netbeans tell me the following:

'.' expected

I have tried the following formatting:

import htmluni-2.15;
import htmlunit-2.15.*;
import Htmlunit;
import Htmlunit.*;

I have read other threads here, but do not understand to the fullest how I accomplish this.

Image: [http://s8.postimg.org/7ru7csh5h/import.png][1]

Upvotes: 1

Views: 188

Answers (2)

kris14an
kris14an

Reputation: 751

Create new project Maven->Java Appliacation. Find file pom.xml, and add this

<dependencies>
    <dependency>
        <groupId>net.sourceforge.htmlunit</groupId>
        <artifactId>htmlunit</artifactId>
        <version>2.4</version>
    </dependency>
</dependencies>

Maven automatically download the library and add them to project.

Upvotes: 0

meliniak
meliniak

Reputation: 772

It doesn't work that way, you import in your code actual classes, not jars. I suggest you reading more about classpath, since it's a basic topic.

Probably you need to open the jar archive and see it's internal directory structure. When a class you are interested in a class is located, say, under file.jar -> com/example/Utils.class, you need to import it using:

import com.example.Utils

Upvotes: 3

Related Questions