简体   繁体   English

-cp 和 -classpath 有什么区别

[英]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?在 CMD 中?

They are the same, check http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html 它们是相同的,请查看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. -classpath classpath -cp classpath指定用于搜索类文件的目录,JAR文件和ZIP存档的列表。 Separate class path entries with semicolons (;). 用分号(;)分隔类路径条目。 Specifying -classpath or -cp overrides any setting of the CLASSPATH environment variable. 指定-classpath或-cp会覆盖CLASSPATH环境变量的任何设置。

If -classpath and -cp are not used and CLASSPATH is not set, then the user class path consists of the current directory (.). 如果未使用-classpath和-cp且未设置CLASSPATH,则用户类路径由当前目录(。)组成。

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. 作为一种特殊的方便,包含基本名称*的类路径元素被认为等同于指定扩展名为.jar或.JAR的目录中所有文件的列表。 A Java program cannot tell the difference between the two invocations. Java程序无法区分两次调用之间的区别。

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. 例如,如果目录mydir包含a.jar和b.JAR,则类路径元素mydir / *将扩展为A.jar:b.JAR,但jar文件的顺序未指定。 All jar files in the specified directory, even hidden ones, are included in the list. 指定目录中的所有jar文件,甚至是隐藏的文件都包含在列表中。 A class path entry consisting simply of * expands to a list of all the jar files in the current directory. 简单地由*组成的类路径条目扩展为当前目录中所有jar文件的列表。 The CLASSPATH environment variable, where defined, will be similarly expanded. 定义的CLASSPATH环境变量将同样进行扩展。 Any class path wildcard expansion occurs before the Java VM is started. 任何类路径通配符扩展都在Java VM启动之前发生。 No Java program will ever see wild cards that are not expanded except by querying the environment. 除了查询环境之外,任何Java程序都不会看到未扩展的外卡。 For example, by calling System.getenv("CLASSPATH"). 例如,通过调用System.getenv(“CLASSPATH”)。

There's absolutely no difference. 绝对没有区别。 It just tells the Java compiler you want to use a custom classpath specified on the command line argument. 它只是告诉Java编译器您要使用命令行参数中指定的自定义类路径。

So -cp and -classpath are fully equivalent. 所以-cp-classpath是完全等价的。

You can find more info on javac - Java programming language compiler page. 您可以在javac - Java编程语言编译器页面上找到更多信息。

There is none. 空无一人。 They're both options for setting the classpath. 它们都是设置类路径的选项。 See the man page . 请参见手册页

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM