Search code examples
javaclasspath

Is `java -cp` simply an abbreviation for `java -classpath`?


On the command line is java -cp simply an abbreviation for java -classpath?

(I seem to remember they may have different behaviour but can't find explicit documentation).


Solution

  • They used to be different, but now they're the same (hence accepting both for compatibility). Originally, -classpath needed to have the classes.zip (Java 1.0/1.1) or rt.jar (Java 1.2+) in order to be able to function. Therefore, if you ran -classpath my.jar, it wouldn't work (since it wouldn't find java.lang.Object and friends). As a result, -cp was added which would append the classpaths/jars to the list, but not overwriting the classes.zip/rt.jar entry.

    However, this behaviour changed sometime (1.4? 1.5?) so that you no longer needed to put entries on the 'system' classpath via -classpath, after which they were identical.

    You could probably run commands from the 1.3 or 1.4 era (if you still have them) to verify when the change occurred.