Javac vs Java in -classpath选项 [英] Javac vs Java within -classpath option
问题描述
从 javac
和 java调用
-classpath
选项有什么区别?
What is the difference in calling the -classpath
option from javac
and from java
例如:
javac -classpath MyJar.jar GetJar.java
java -classpath MyJar.jar:. GetJar
它的工作原理如下:
javac -classpath MyJar.jar GetJar.java
java GetJar
所以基本上需要存在与 javac
相关的第一个类路径,另一方面在java命令行中它可能是可选的。为什么?你知道在什么情况下它是强制性的。更一般地说, javac
调用的 -classpath
的影响是什么?<$ c $的影响是什么c> -classpath 由 java
调用。
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
.
提前致谢。
推荐答案
一个是用于编译的类路径。另一个是用于运行的类路径。而且他们 不 必须是同一件事。编译过程所需的类集是所有正在编译的类所引用的类。而您的运行时JAR可能正在调用一个空主方法且没有依赖关系的独立类。
One is the classpath used for compiling. The other is the classpath used for running. And they do not have 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.
请记住,在运行时类依赖关系是动态解析的,也就是一个类只是在需要时加载(这是一般化,引导和系统类总是加载)。
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 always loaded).
这篇关于Javac vs Java in -classpath选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!