-classpath 选项中的 Javac 与 Java [英] Javac vs Java within -classpath option
问题描述
从 javac
和从 java
例如:
javac -classpath MyJar.jar GetJar.java
java -classpath MyJar.jar:. GetJar
它的作用和:
javac -classpath MyJar.jar GetJar.java
java GetJar
所以基本上与 javac
相关的第一个 -classpath 需要在那里,另一方面,在 java 命令行中它可能是可选的.为什么?你知道在什么情况下它是强制性的吗?更一般地说,javac
调用的 -classpath
的作用是什么,java<调用的
-classpath
的作用是什么?/代码>.
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 可能会调用具有空 main 方法且没有依赖项的独立类.
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).
这篇关于-classpath 选项中的 Javac 与 Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!