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.

2
  • 3
    You may want to consider bundling the JVM with the JAR. It will be about 80MB, but there are many tools to make it very easy. Commented Jan 13, 2016 at 5:26
  • 1
    why.do.you.put.periods everywhere? Commented Jan 13, 2016 at 5:46

3 Answers 3

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/

Sign up to request clarification or add additional context in comments.

2 Comments

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
javapackager was available in Java 7, but it was called javafxpackager.
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

1 Comment

Before you do, see Is GNU's Java compiler GCJ dead? Also the GCJ News page, which hasn't been updated since 2009.
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.

2 Comments

GCJ is at considerably less than 1.5 level. Major parts of 1.3 are not complete, ditto 1.3 and 1.4.
@EJP: better now ? ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.