java - java 命令的 -jar 选项的真正作用是什么

标签 java jar

java 命令的 -jar 选项是否也会在运行 main 方法之前编译源代码? 我相信是这样,但我想更好地了解内部流程,从手册页中您可以清楚地看到一个小的工作流程序列:

-jar
             Execute a program encapsulated in a JAR file. The first argument is the name of a JAR file instead of a startup class name. In order for this option to work, the manifest of the JAR file must contain a  line  of
             the form Main-Class: classname. Here, classname identifies the class having the public static void main(String[] args) method that serves as your application's starting point. See the Jar tool reference page and
             the Jar trail of the Java Tutorial @

但它没有提到它编译源代码。

最佳答案

Does the -jar option of the java command also compile the sources before running the main method?

不,绝对不是。它只是指定 jar 文件,在该文件中查找指定主类的 list ,以及(通常)该类的类文件。它绝对不会编译任何东西。

关于java - java 命令的 -jar 选项的真正作用是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24033212/

相关文章:

java - 在代码中获取 AWS Lambda 函数的别名

java - 更改字符串中的某些字符

java - 通过类型索引为 0 的构造函数参数表示的 Spring 不满足的依赖关系

Java 注解不适用于外部 Jar 文件

java - 将新数组分配给现有数组的正确方法

java - 反射 - 示例代码 - ClassNotFoundException 错误

java - 如何知道正在运行的 jar 的名称

java - 将 Java jar 中文本文件的路径传递给 C 库?

java - Jar 和文件 I/O

java - 替换 jar 文件中文件夹内的类文件