Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between -cp and -classpath

What's the difference between using

javac -cp classes helloworld.java

and

javac -classpath classes helloworld.java

in CMD?

like image 511
root Avatar asked Apr 03 '15 14:04

root


3 Answers

They are the same, check http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html

-classpath classpath -cp classpath Specifies a list of directories, JAR files, and ZIP archives to search for class files. Separate class path entries with semicolons (;). Specifying -classpath or -cp overrides any setting of the CLASSPATH environment variable.

If -classpath and -cp are not used and CLASSPATH is not set, then the user class path consists of the current directory (.).

As a special convenience, a class path element that contains a base name of * is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. A Java program cannot tell the difference between the two invocations.

For example, if directory mydir contains a.jar and b.JAR, then the class path element mydir/* is expanded to a A.jar:b.JAR, except that the order of jar files is unspecified. All jar files in the specified directory, even hidden ones, are included in the list. A class path entry consisting simply of * expands to a list of all the jar files in the current directory. The CLASSPATH environment variable, where defined, will be similarly expanded. Any class path wildcard expansion occurs before the Java VM is started. No Java program will ever see wild cards that are not expanded except by querying the environment. For example, by calling System.getenv("CLASSPATH").

like image 170
JFPicard Avatar answered Oct 14 '22 21:10

JFPicard


There's absolutely no difference. It just tells the Java compiler you want to use a custom classpath specified on the command line argument.

So -cp and -classpath are fully equivalent.

You can find more info on javac - Java programming language compiler page.

like image 4
abarisone Avatar answered Oct 14 '22 21:10

abarisone


There is none. They're both options for setting the classpath. See the man page.

like image 1
Sotirios Delimanolis Avatar answered Oct 14 '22 21:10

Sotirios Delimanolis