Question

I am using Netbeans IDE for a java project. In this project i need a jar file "htmlunit-2.6.jar".

I have included this jar file in the project libraries folder. I have instantiated one of its class "WebClient" but this class needs other classes of "commons-httpclient-3.1.jar" file.

Now I have also included "commons-httpclient-3.1.jar" file in the project libraries folder. But when I compiled my source file, it throws

ClassNotFoundException: org.apache.commons.httpclient.auth.CredentialsProvider

Kindly tell me how to handle this situation when one class in one jar file needs other classes in other jar file.

Was it helpful?

Solution

Simply put the required jar files on the classpath at compile-time and it should work. If you were doing it from the command-line then it would look like this:

javac -cp jar1:jar2 my.Application

If you are using NetBeans then you need to tell NetBeans that both of the JARs are on your classpath. It will be definable in a Project > Properties wizard as described here and also here from the tutorial

OTHER TIPS

The ClassNotFoundException tells you that your libraries have some dependencies that you don't have included in your classpath at runtime. Your source is OK, because if you have used something not available, NB will tell you this at compile time (or before when editing).

So, welcome in the "dependency hell" of Java. For small projects you will be able to check all dependencies by hand with readme files, docs, etc and put them in the project config as oxbow_lakes said. For bigger things look at maven. It will do (most) everything for you !

(Maven is available in NB6)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top