-classpath 选项中的 Javac 与 Java
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15121697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javac vs Java within -classpath option
提问by Rollerball
What is the difference in calling the -classpath
option from javac
and from java
-classpath
从javac
和从调用选项有什么区别java
for example:
例如:
javac -classpath MyJar.jar GetJar.java
java -classpath MyJar.jar:. GetJar
it works as well as:
它的工作原理和:
javac -classpath MyJar.jar GetJar.java
java GetJar
So basically where the first -classpath related to javac
needs to be there, on the other hand in the java command line it might be optional. Why? Do you know in which circumstance it would be mandatory. And more in general what is the effect of -classpath
called by javac
and what is the effect of -classpath
called by java
.
所以基本上第一个相关的 -classpathjavac
需要在那里,另一方面在 java 命令行中它可能是可选的。为什么?你知道在什么情况下它是强制性的吗?更一般地说,被-classpath
调用的效果是javac
什么以及-classpath
被调用的效果是什么java
。
Thanks in advance.
提前致谢。
回答by Perception
One is the classpath used for compiling. The other is the classpath used for running. And they do nothave to be the same thing. The set of classes needed for the compilation processes are all those referred to by every class being compiled. Whereas your runtime JAR could be invoking a standalone class with an empty main method and no dependencies.
一种是用于编译的类路径。另一个是用于运行的类路径。而且他们不必须是同样的事情。编译过程所需的类集是被编译的每个类所引用的所有类。而您的运行时 JAR 可能正在调用具有空 main 方法且没有依赖项的独立类。
Just remember that at runtime class dependencies are resolved dynamically, aka a class is only loaded when it is needed (this is a generalization, boot and system classes are alwaysloaded).
请记住,在运行时类依赖项是动态解析的,也就是类仅在需要时才加载(这是一种概括,引导和系统类始终加载)。
回答by Lemon Juice
This document contains answers for your questions
本文档包含您问题的答案
http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/javac.html
http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/javac.html
using -classpath
every time is a very time consuming work. Instead, use environment variables (if you are dealing with a package such as Java Mail)
-classpath
每次使用都是非常耗时的工作。相反,使用环境变量(如果您正在处理诸如 Java Mail 之类的包)
classpath is used for compiling. Javac
is the Java Compiler, where it converts your code into byte code.
类路径用于编译。Javac
是 Java 编译器,它将您的代码转换为字节码。
When it comes to java
it is used to run your Java source file/jar.
说到java
它用于运行您的 Java 源文件/jar。