1

I have 3 jar files A.jar, B.jar, C.jar. C.jar contains a class com.rb.test.PResolver.java having main method. C.jar has dependency on A.jar and B.jar. When I try to run PResolver class using following command, the main method gets invoked, but it fails, since the dependent jar files are not in classpath:

java -cp C.jar com.rb.test.PResolver

When I try to add the dependent jar filed in -CP option, then the class is not found:

java -cp A.jar:B.jar:C.jar com.rb.test.PResolver

Above command gives following error:

Error: Could not find or load main class com.rb.test.PResolver

So the moment I put the dependent jars in the -cp option of java command, the class is not found.

Rajib Biswas
  • 772
  • 10
  • 27

1 Answers1

1

Place all your jar files in a folder lib and then try:

  • for unix: java -cp C.jar:lib/*:. com.rb.test.PResolver
  • for Windows: java -cp C.jar;lib\*;. com.rb.test.PResolver

Refer to this question for details to see how you can execute jar with multiple classpath libraries from command line

Ravik
  • 694
  • 7
  • 12