B4J Tutorial Create Windows native executables (exe files)

Not open for further replies.
This tutorial is no longer relevant. Use B4JPackager11: B4JPackager11 - the simplest way to distribute UI apps
When you compile in Release mode the complete app is packed as an executable jar file.

You can distribute this jar file and run it on Windows, Mac or Linux.

However there are cases where you want to convert this jar file to a native executable. For example if you want to set a custom icon.

You can use a free tool named Launch4j to convert the jar file to a native Windows executable.

1. Download Launch4j: http://sourceforge.net/projects/launch4j/files/launch4j-3/
2. Compile your app in Release mode.
3. Set the icon and other required parameters:



4. Click on the Build Wrapper button.


The output will be a standard Windows executable.

For example:

Another distribution option: https://www.b4x.com/android/forum/threads/ui-apps-packaging-self-contained-installers.56854/
B4J Packager will create a single installer file that includes an embedded Java Runtime.
Last edited:


Licensed User
Hi Margret,
you're thinking of deploying a single exe file.
L4J does not do this, because it is not an installer.
Exe file generated by L4J is a custom zip file.
By changing the extension from exe in the zip, find the contents of your jar file.
The exe file is a little bigger (31 kb) of the jar.
If you want to distribute a single EXE file, you can always just make a zip exploding, a folder that contains the EXE file created with L4J and a jre subdirectory that contains the copy of the JRE that you need.



Active Member
Licensed User
We have programs that do what you wish for. But I do not know how.
One of the programs is named ProjectX. It is a Java development and one chap has built it as a standalone exe and if I remember correct is about 6MB in download size.
Maybe it would be worth searching out. ProjectX


There is a link down the page where the Java is included.

Hope that may be of some help.


Well-Known Member
Licensed User
The issue is that the jre is 122meg. The .EXE file is only 312kb. I just wish I had a conditional compiler that would pull in only the required support from the jre and bundle it within the .EXE file. The whole project would most likely be less than a meg or two.

I have not tried either of these yet, but maybe JSmooth or Excelsior could work for you.


or this one:


Hope that's what your need.
Last edited:

Gaver Powers

Licensed User
Not certain if this helps or not...


Includes a lot of discussion regarding bundling the JRE. (more in the link above)

Required element that groups JRE settings.
<path>, <minVersion>, <maxVersion>
The <path> property is used to specify the absolute or relative path (to the executable) of a bundled JRE, it does not rely on the current directory or <chdir>. Note that this path is not checked until the actual application execution. If you'd like the wrapper to search for a JRE (public or SDK private) use the <minVersion> property, you may also specify the <maxVersion> to prevent it from using higher Java versions. Launch4j will always use the highest version available (in the min/max range of course). If a Sun's JRE is not available or does not satisfy the search criteria, the search will be repeated on IBM runtimes. You can also combine these properties to change the startup process...

There's also more than 100 hits in their forum on the subject of Bundle JRE

http://sourceforge.net/p/launch4j/discussion/search/?q=bundle jre

This one seems pertinent


Last edited:


Well-Known Member
Licensed User
... if your app doesn't work when you double click on the jar file ...
Thats my problem.
When I compile in "Release Mode", the Program starts and works well. I can see that in the Log-file.
It generates a result in the folder "Objects" named "DataCollectionServer.jar". When I doubleclick on this jar file, an error message apears: "A Java Exception has occured:" (see PNG-File)

The same error message apears after generating and clicking on the Windows.exe file. What is the problem solution?


  • - Java Error Message -.png
    - Java Error Message -.png
    25.1 KB · Views: 658


Well-Known Member
Licensed User
Hello Erel,
thank you for your help!
Try to run it from the command line with java -jar <your jar name>
You will see the error message.

Also run java -version

My guess is that the default java is an older version of java.
I did what you said.
A DOS-Window apeared just for some milliseconds and I couldn't read the information.
Do you know how to stop the window to remove from the screen?


Well-Known Member
Licensed User
oops you where faster ...

Do you know how to stop the window to remove from the screen?
The solution is: Writing "cmd" into the command line and click Enter. A DOS-Window apears and you can see everything.

But there's no error message everything seems OK (see attached file)?


  • - Java Error Message 2 -.png
    - Java Error Message 2 -.png
    49.3 KB · Views: 549


Active Member
Licensed User
I have the same problem to start .jar file wrapped to .exe.
You can see the error message in attached file below.
What can cause this error?


  • jarproblem.JPG
    171.6 KB · Views: 483


Well-Known Member
Licensed User
Hi @Erel.
There are some additional settings to do in launch4j in order to start a web socket server ?


Well-Known Member
Licensed User
I did try to make exe ... I did succeded to the point where i must open the file ...
I get the error invalid or corupt jar file

I can not run the original jar file on windows ...I have to make it application .exe?
Not open for further replies.