2

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.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Rasa
  • 31
  • 4

3 Answers3

4

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/

user882813
  • 813
  • 5
  • 16
  • I think the self-contained packages are the best option: standard, no cost and does the job. Plus you don't need the source, it works on JARs – Marged Jan 13 '16 at 07:16
  • `javapackager` was available in Java 7, but it was called `javafxpackager`. – Eng.Fouad Jan 13 '16 at 07:18
1

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

Klssr_King
  • 54
  • 4
  • 1
    Before you do, see [Is GNU's Java compiler GCJ dead?](http://stackoverflow.com/questions/4035538/is-gnus-java-compiler-gcj-dead/4040404#4040404) Also the [GCJ News page](http://gcc.gnu.org/java/), which hasn't been updated since 2009. – user207421 Jan 13 '16 at 05:29
0

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.

Marged
  • 10,577
  • 10
  • 57
  • 99