tags:

views:

135

answers:

3

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 (@AlBlue) for confirming that my memory was in fact correct and that they used to be different.

+6  A: 

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.

BalusC
Thanks - I read this but also noted that other commands mentioned synonyms explicitly. I also wasn't clear what "A" means and whether it specifically related to the last option
peter.murray.rust
It's just English. Maybe the semicolon was a bit confusing. You should read it as "A semicolon separated list ...". In *nix (Unix, Linux and clones) it's by the way a colon `:`.
BalusC
'A' in that document is just an indefinite article at the beginning of a sentence :)
Carl Smotricz
@Carl - Be gentle with him. English is obviously not his first language :-)
Stephen C
The 'A' is for 'A semicolon list of directories' or, on Linux/Mac, 'A colon list of directories'. Unfortunately the use of the symbol, which can also be interpreted as a valid grammatical character in prose.
AlBlue
A: 

See the JDK Tools and Utilities documentation for info on command line parameters.

McDowell
+7  A: 

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.

AlBlue