Differences between “java -cp” and “java -jar”?

I prefer the first version to start a java application just because it has less pitfalls (“welcome to classpath hell”). The second one requires an executable jar file and the classpath for that application has to be defined inside the jar’s manifest (all other classpath declaration will be silently ignored…). So with the second version you’d have to look into the jar, read the manifest and try to find out if the classpath entries are valid from where the jar is stored… That’s avoidable.

I don’t expect any performance advantages or disadvantages for either version. It’s just telling the jvm which class to use for the main thread and where it can find the libraries.

Leave a Comment