What is the difference between -cp and -classpath

What is the difference between using

javac -cp classes helloworld.java

and

javac -classpath classes helloworld.java

in CMD?

+6
source share
3 answers

They are the same, check out 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 a semicolon (;). Specifying -classpath or -cp overrides any configuration of the CLASSPATH environment variable.

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

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

For example, if the mydir directory contains a.jar and b.JAR, then the class path mydir / * decrypts to A.jar: b.JAR, except that the order of the jar files is not specified. All jar files in the specified directory, even hidden ones, are included in the list. The path to the entry class, consisting simply of *, expands to a list of all jar files in the current directory. CLASSPATH environment variable, where defined in the same way. Any extension to a group class template occurs before the Java virtual machine starts. No Java program will ever see wild cards that are not extended except by querying the environment. For example, calling System.getenv ("CLASSPATH").

+4
source

Absolutely no difference. It simply tells the Java compiler that you want to use your own class path specified in the command line argument.

So, -cp and -classpath completely equivalent.

Learn more about javac - the Java programming language compiler .

+2
source

No. Both of these are options for setting the class. See the man page .

+1
source

Source: https://habr.com/ru/post/984655/


All Articles