How to handle two jar files in java?

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

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

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

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

Tell me how to handle this situation where one class in one jar file needs other classes in another jar file.

+2


source to share


2 answers


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

javac -cp jar1:jar2 my.Application

      



If you are using NetBeans

then you need to advise NetBeans

that both JARs are in your classpath. It will be defined in the Project Wizard> Properties as described here and also here from the tutorial

+5


source


The NotFoundException class tells you that your libraries have some dependencies that you did not include in your classpath at runtime. Your source is fine, because if you used something not available NB will report it at compile time (or before editing).

So, welcome to Java Adventure Hell . For small projects, you should be able to check all dependencies manually using readme files, docs, etc. And put them in the project config like oxbow_lakes said. For big things see maven . This will do (most) everything for you!



(Maven is available in NB6)

0


source







All Articles