18

I want to run a java program as an exe in Windows. The windows box doesn't install java at all...

So, is there any other way in which the java program can be converted to an exe which removes the need for a dependency on the JRE?

CJBS
  • 15,147
  • 6
  • 86
  • 135
siva
  • 1,105
  • 4
  • 19
  • 38

9 Answers9

9

You can ship the JRE with your application and use that JRE for your application. The effect is the same: The application will be started through an executable (wrapper needed) or script (batch) file and the target machine does not need to have a java runtime installed.

Java doesn't have to be 'installed', it just has to be 'present'.

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
8

You can use Excelsior JET compiler for that purpose.

See http://www.excelsiorjet.com/ for more information on this.

Dmitry Leskov
  • 3,233
  • 1
  • 20
  • 17
Vanya
  • 3,091
  • 2
  • 18
  • 12
  • 1
    2023: This domain seems to be for sale. the topic seems to be outdated, wrong or incomplete :( And the question is so good! – f b Jul 23 '23 at 19:23
1

For the application to run you will need the runtime. In fact the very first thing that happens when you start the app is a call is a made to OS to start JRE. You cannot do without JRE.

[You can of course embded JRE into your app itself if you want].

Sesh
  • 5,993
  • 4
  • 30
  • 39
  • As far as I know, you're not wrong, but I'm curious; why is this the case? There are a few different utilities (py2exe is one) which package the Python interpreter with an installer. – Imagist Aug 26 '09 at 05:44
  • 1
    The whole point of virtual machines is that you want to abstract the application from the underlying OS. Another example is garbage collection. There is no way garbage collection is going to work without someone overlooking the application and taking care of releasing memory when the object goes out of scope. This is done by the JRE. – Sesh Aug 26 '09 at 06:17
  • @Sesh The other answers demonstrate that this is wrong. A replacement for JRE (which is what the other answers are about) is what's needed. There's nothing magical about JRE; you could have an alternate engine to do stuff like garbage collection. – Patrick Oct 24 '18 at 03:36
1

I have used JSmooth to exify my application. It also allows for embedding a JRE inside. I just used the "ensure that at least Java X is available".

GPL, can be run as an ant task.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
1

Well given the fact, that you are requesting an executable file (exe) in Windows, there is another approach:

Use IKVM.NET - Bytecode Compiler which converts Java bytecode to .NET dll's and exe's.

Get the latest version of IKVM.NET here.

Use this command

 ikvmc -target:exe -out:foo.exe yourJarFile.jar

to create your .NET executable file.

After this, you can use your exe with the mandatory IKVM dll's or if you prefer one exe file, you can use ILMerge in order to get a single executable file:

ILMerge.exe /target:winexe /targetplatform:"v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1" /out:C:\foo\bar.exe foo.exe <IKVM dll's>.dll
Baccata
  • 473
  • 1
  • 7
  • 15
  • This worked nicely for me. Except IKVM had trouble seemingly with later versions of Java. I had to change my target java version. Also it only seems to be able to produce binaries with .NET version 3.5 (would have preferred .NET 2). – Patrick Oct 22 '18 at 06:34
1

If you are using JDK 9 and above then you can use jlink. It will include all the necessary modules, header files, security policy files, etc, and build a minimal runtime image. This image can be shipped directly to the customer. You can specify your own launcher and what not.

jlink description:

You can use the jlink tool to assemble and optimize a set of modules and their dependencies into a custom runtime image.

Read more at oracle docs: Java Platform, Standard Edition Tools Reference.

Aniket Sahrawat
  • 12,410
  • 3
  • 41
  • 67
0

GCJ can create native code from Java source files. Here's a tutorial on how to build it in Windows.

Cinder6
  • 566
  • 2
  • 10
0

Have you tried install4j? There are various versions, some free, of this concept. Basically, this application compiles your application into an executable installer, specific to the OS of your choice.

Yuval
  • 7,987
  • 12
  • 40
  • 54
0

Easiest way to do this task is to use the launch4j for the windows exe wrapper and then use inno setup to create the installer. When you are creating the installer for the you application add the folder under the other application files. Make sure jre is inside the folder.

Work done!!!