Reputation: 31
I have a Java program which is converted as executable jar. Is it possible to run the jar in Linux machine where Java is not available? I.e a machine that has no Java.
Upvotes: 2
Views: 1186
Reputation: 10973
If your application does not make use of the latest Java language standards you can use gcj to create a binary. But please consider that gcj is a rather old product that was not updated for years. The support of newer Java versions is lacking, the project page states:
... has been merged with GNU Classpath and supports most of the 1.4 libraries plus some 1.5 additions.
Code created by gcj might be considerably slower than code run under a Hotspot Jvm and creates rather big binaries when compiled statically.
Another option is to bundle a Jre and your jar into an executable. There are several programs for this task, launch4j (http://launch4j.sourceforge.net) is one of them.
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. If you use Oracles JRE check the Eula if it is allowed to bundle it this way. If not you can use OpenJdk.
Upvotes: 0
Reputation: 835
In Java 8 you can create so called "self-contained packages" for Windows/Linux/Mac which in fact is java applications bundled with JRE.
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/packager.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/
Upvotes: 4
Reputation: 54
Try this Compiler. 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
Upvotes: 1