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?