Shahab
Shahab

Reputation: 2067

Import jar class into java program

I have this servlet program and an external .jar file (written by someone else) that I want to call to. I basically want to import one of the classes located in the jar file because it has a method that I need to call. Is this possible?

Currently, the previous programmer was able to call to the class (I want) by simply:

import Validator.validate;

Now the name of the .jar is

BugValidator.jar

I've tried implementing the above code to no sucees, is there a specific location the file needs to be in? I am using netbeans 7.1, so should I add it to the filepath?

Upvotes: 0

Views: 1123

Answers (1)

Aaron Digulla
Aaron Digulla

Reputation: 328594

Copy the JAR file into WEB-INF/lib. The container will automatically add it to the classpath if it's in this folder.

[EDIT] Inside Netbeans, you'll have to add the JAR manually. Right click on "Libraries" -> "Add JAR/Folder..."

Upvotes: 1

Related Questions