1

I launch my application with java -cp dependencyJarPath -jar MyJar.jar. But it can not find the class in my dependencyJar and gives me java.lang.NoClassDefFoundError . Then I print the classpath in my code and find that dependencyJarPath is not on my classpath. Then I add the dependencyJarPath in the Class-Path header in the MANIFEST.MF of my jar and launch my application with java -jar MyJar.jar, it worked.

So my question is when use -cp and -jar toghter, will -cp take effect? If it does not take effect, how could I set the classpath when running my jar other than set the Class-Path header?

haoyu wang
  • 1,241
  • 4
  • 17

1 Answers1

2

according to this: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html

"When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored."

if you don't mind specifiying the startup class on launching the application, you can add your jar to the classpath and start it like that.

java -cp dependencyPath;MyJar.jar My.StartUpClass
Andi
  • 162
  • 9