简体   繁体   English

创建java可执行文件

[英]Creating a java executable

What is the command-line equivalent (Linux) of 什么是命令行等效(Linux)

gcc -o executable file.c

for a jar file? 对于一个jar文件? (Java instead of gcc) (Java而不是gcc)

I know it is possible to do because at my school, all that is necessary is writing "mars" (the MIPS simulator) in command-line 我知道这是可能的,因为在我的学校,所有必要的是在命令行中编写“火星”(MIPS模拟器)

To execute a Java JAR file, run the following command, replacing YourJarFile.jar with the filename of your JAR file. 要执行Java JAR文件,请运行以下命令,将YourJarFile.jar替换为JAR文件的文件名。

java -jar YourJarFile.jar

EDIT: There is no way to execute a Java JAR like 编辑: 没有办法像Java一样执行Java JAR

./YourJarFile.jar

because the Java Runtime Environment must interpret the JAR file, not the operating system's sh . 因为Java运行时环境必须解释JAR文件,而不是操作系统的sh

There is no direct, native, command-line equivalent. 没有直接的,本机的命令行等价物。 @Deltik provides the closest compatible method. @Deltik提供最接近的兼容方法。

javac myfile.java

假设你安装了JDK;)

To compile Foo.java and Bar.java: 编译Foo.java和Bar.java:

javac Foo.java Bar.java

To put the compiled class files in a jar: 要将已编译的类文件放在jar中:

jar cvf classes.jar Foo.class Bar.class

Note that if you put your classes in packages, which you should, your class files will be in a sub-directory and you will have to change the jar command accordingly. 请注意,如果您将类放在包中,那么您的类文件将位于子目录中,您必须相应地更改jar命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM