简体   繁体   English

在Linux环境中在没有JVM的情况下运行Java

[英]Run Java without JVM in Linux environment

I have a Java program which is converted as executable jar. 我有一个转换为可执行jar的Java程序。 Is it possible to run the jar in Linux machine where Java is not available? 是否可以在Java不可用的Linux机器上运行jar? Ie a machine that has no Java. 即一台没有Java的机器。

In Java 8 you can create so called "self-contained packages" for Windows/Linux/Mac which in fact is java applications bundled with JRE. 在Java 8中,您可以为Windows / Linux / Mac创建所谓的“自包含程序包”,实际上是与JRE捆绑在一起的Java应用程序。

Future reading: 未来阅读:

https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/self-contained-packaging.html https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/self-contained-packaging.html

https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/packager.html https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/packager.html

https://docs.oracle.com/javase/8/docs/technotes/tools/unix/javapackager.html https://docs.oracle.com/javase/8/docs/technotes/tools/unix/javapackager.html

Also it may be worth to mention ahead of time (AOT) Java compilers such as Excelsior Jet: http://www.excelsiorjet.com/ 另外,可能值得一提的是提前(AOT)Java编译器,例如Excelsior Jet: http : //www.excelsiorjet.com/

Try this Compiler. 试试这个编译器。 https://en.wikipedia.org/wiki/GNU_Compiler_for_Java https://en.wikipedia.org/wiki/GNU_Compiler_for_Java

The GNU Compiler for Java (GCJ) is a free compiler for the Java programming language and a part of the GNU Compiler Collection GNU Java编译器(GCJ)是Java编程语言的免费编译器,并且是GNU Compiler Collection的一部分。

If your application does not make use of the latest Java language standards you can use gcj to create a binary. 如果您的应用程序未使用最新的Java语言标准,则可以使用gcj创建二进制文件。 But please consider that gcj is a rather old product that was not updated for years. 但是请考虑一下gcj是一个相当老的产品,多年来没有更新。 The support of newer Java versions is lacking, the project page states: 缺少对较新Java版本的支持,该项目页面指出:

... has been merged with GNU Classpath and supports most of the 1.4 libraries plus some 1.5 additions. ...已与GNU Classpath合并,并支持大多数1.4库和1.5个附加库。

Code created by gcj might be considerably slower than code run under a Hotspot Jvm and creates rather big binaries when compiled statically. 由gcj创建的代码可能比在Hotspot Jvm下运行的代码要慢得多,并且在静态编译时会创建相当大的二进制文件。

Another option is to bundle a Jre and your jar into an executable. 另一个选择是将Jre和jar捆绑到可执行文件中。 There are several programs for this task, launch4j ( http://launch4j.sourceforge.net ) is one of them. 有许多程序可以执行此任务,launch4j( http://launch4j.sourceforge.net )是其中之一。

You could also provide Java yourself as it does not need to be installed and can be put into the same directory as your jar. 您也可以自己提供Java,因为它不需要安装,并且可以与jar放在同一目录中。 If you use Oracles JRE check the Eula if it is allowed to bundle it this way. 如果使用Oracle JRE,请检查Eula是否允许以这种方式捆绑它。 If not you can use OpenJdk. 如果没有,您可以使用OpenJdk。

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

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