peter.murray.rust
peter.murray.rust

Reputation: 38033

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).

Upvotes: 3

Views: 488

Answers (3)

AlBlue
AlBlue

Reputation: 24040

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.

Upvotes: 8

McDowell
McDowell

Reputation: 108879

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

Upvotes: 0

BalusC
BalusC

Reputation: 1108692

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.

Upvotes: 8

Related Questions