Is `java -cp` simply an abbreviation for `java -classpath`?
On the commandline
is java -cp
simply an abbreviation for java -classpath
?
(I seem to remember they may have different behaviour but can't find explicit documentation).
UPDATE Thanks (@AlBl开发者_StackOverflowue) for confirming that my memory was in fact correct and that they used to be different.
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.
In Windows,
java -help
says under each
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
Looks pretty clear. They both does the same. So, yes, it's an alias.
See the JDK Tools and Utilities documentation for info on command line parameters.
精彩评论