Running a java program as an exe in Windows without JRE installed
Asked Answered
H

8

20

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?

Hildegardhildegarde answered 26/8, 2009 at 5:39 Comment(0)
S
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'.

Schweiz answered 26/8, 2009 at 7:16 Comment(2)
Can you? Like legally? Oracle doesn't allow Linux distros to include the JRE in my experience. I imagine apps have similar distribution concerns.Meaningful
Standard way of doing thisIcecold
M
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].

Monamonachal answered 26/8, 2009 at 5:41 Comment(3)
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.Tetralogy
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.Monamonachal
@Monamonachal 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.Stroud
L
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.

Lombok answered 26/8, 2009 at 9:11 Comment(0)
S
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
Stallings answered 15/9, 2017 at 9:57 Comment(1)
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).Stroud
I
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.

Icecold answered 20/4, 2021 at 5:11 Comment(0)
M
0

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

Memorialize answered 26/8, 2009 at 5:47 Comment(3)
can you tell, how good does GCJ deal with Java 1.5 and 1.6 features?Lumper
Last I knew, it's only working with JDK 1.4, which is too bad.Memorialize
GCJ has been dead for many years, including the year this was posted.Fluorometer
C
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.

Cambell answered 26/8, 2009 at 9:27 Comment(0)
A
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!!!

Allier answered 9/6, 2021 at 13:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.