java 在 linux 中运行从 windows 创建的 jar 文件作为可执行文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14558479/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 16:40:27  来源:igfitidea点击:

run the jar file created from windows in linux as executable

javalinuxjarexecutable-jar

提问by adesh singh

Hi I have developed a swing application using javafxon Windows operating system . It's working fine on Windows. But when I run the jar on Linux it's defaulting to opening in the archive manager, it's not working as an executable.

嗨,我开发了一个javafx在 Windows 操作系统上使用的 Swing 应用程序。它在 Windows 上运行良好。但是当我在 Linux 上运行 jar 时,它默认在存档管理器中打开,它不能作为可执行文件运行。

I have checked the properties of the jar file, it's an executable already.

我已经检查了 jar 文件的属性,它已经是一个可执行文件。

Do I have to recompile the source file in a Linux environment to run this jar fileon Linux or will the jar filework on Linux also?

我是否必须在 Linux 环境中重新编译源文件才能在 Linux 上运行它jar file,还是也jar file可以在 Linux 上运行?

回答by Vahid Farahmand

If you've not used an operating system dependent commands like running a windows command from java (which will not run in linux for sure) or using a windows specific module, your java will run in all other operating systems. This is one of the most significant features of java which is cross-platform and you can run your code in different operating systems which has that operating system specific java runtime environment installed.

如果您没有使用依赖于操作系统的命令,例如从 java 运行 windows 命令(肯定不会在 linux 中运行)或使用 windows 特定模块,那么您的 java 将在所有其他操作系统中运行。这是跨平台的 java 最重要的特性之一,您可以在安装了特定于操作系统的 java 运行时环境的不同操作系统中运行您的代码。

So in all operating systems, just you have to run

所以在所有操作系统中,你只需要运行

java -jar yourjarfile.jar

回答by TheWhiteRabbit

executable jar has to be executable across the operating systems.

可执行 jar 必须可以跨操作系统执行。

However, you need to check the permission of the .jar file . especially when executing in linux like environment.

但是,您需要检查 .jar 文件的权限。特别是在类似 linux 的环境中执行时。

chmod +x /path/to/your/java.jar

use chmod command in linux / modify your buil.xml using Ant chmod

在 linux 中使用 chmod 命令/使用Ant chmod修改您的 buil.xml