-cp和-classpath有什么区别 [英] What's the difference between -cp and -classpath

查看:396
本文介绍了-cp和-classpath有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

javac -cp类helloworld.java

javac -classpath类helloworld.java

在CMD中?

推荐答案

它们是相同的,请检查 http://docs.oracle.com/javase/7/docs/technotes/tools/ windows / java.html

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


-classpath classpath
-cp classpath指定目录,JAR文件,和ZIP存档以搜索类文件。用
分号(;)分隔类路径条目。指定-classpath或-cp会覆盖CLASSPATH环境变量
的任何设置。

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

如果未使用-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 (.).

为方便起见,包含基本
名称的类路径元素*的作用等同于指定目录中所有扩展名为.jar或.JAR的
文件的列表。 Java程序
不能分辨两个调用之间的区别。

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.

例如,如果目录mydir包含a.jar和b.JAR,则
类路径元素mydir / *扩展为A.jar:b.JAR,不同之处在于
jar文件的顺序未指定。指定的
目录中的所有jar文件,甚至是隐藏的jar文件,都包含在列表中。仅由*组成的类路径
条目扩展为当前目录
中所有jar文件的列表。定义
的CLASSPATH环境变量将类似地扩展。任何类路径通配符扩展
都会在启动Java VM之前发生。除非通过查询环境,否则任何Java程序都不会看到没有扩展的
通配符。
例如,通过调用System.getenv( CLASSPATH)。

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

这篇关于-cp和-classpath有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆