B4J Tutorial Runner to start JAR with Open JDK

Note: This wont be for everyone and is not a replacement for B4JPackager11

Also, see @agraham post here; https://www.b4x.com/android/forum/threads/running-jars-under-openjdk-11.106201

I distribute some executable JAR files with a B4J Server application which has a Open JDK runtime included as part of the package.

While I appreciate what B4JPackager11 does this solution wasn't right for me as I don't want multiple runtimes or have to create a new executable for every JAR I make.

Based on Erels C# B4JPackager11 code I have created a C# "runner" which starts the JAR using Open JDK but the executable uses its name to execute the jar in the same directory.

For example;

1) If you start Runner.exe it will launch Runner.jar
2) If you rename Runner.exe to bob.exe it will launch bob.jar (assuming bob.jar exists)
3) If you rename Runner.exe to Config.exe it will launch Config.jar (assuming Config.jar exists)

This way I can have one executable that I can rename to target multiple JAR files.

The code repo is here;

https://github.com/ope-nz/Runner

The pre-compiled exe is here; https://github.com/ope-nz/Runner/blob/master/Runner.exe

If you want to build your own Runner or change the icon there is a batch file to build the C# code for you (download the project).

IMPORTANT: One thing to note is that by default Open JDK isnt in the OS path so Runner looks for a folder called "runtime" in the same folder as Runner.exe and the JDK should be in the runtime folder (see screenshot). The code will also look for a JDK in C:\Java. You can adjust this in the C# code if you want.

In the screenshot you can see Runner.exe has been renamed to Config.exe and this will launch Config.jar (in the same folder) using the Open JDK runtime under the runtime folder.

 
Last edited:

tchart

Well-Known Member
Licensed User
Longtime User
T
This is similar to this thread
Running jars under OpenJDK 11
Thanks @aeric I hadn't seen that. Total coincidence that they were posted around the same time.

Each solution will have benefits and drawbacks.

I built mine based on Erels solution using .Net in order to support executable Jars for distribution with my server app. It assumes the user doesn't have a jre that is registered in the OS path.
 

aeric

Expert
Licensed User
Longtime User
Ya @tchart , this benefits all of us to choose whichever solution that fit to our needs. Thanks to both agraham and you.
 

OliverA

Expert
Licensed User
Longtime User
Note: The link to the Runner.exe file returns a 404 GitHub page. The Runner.exe that is included in the code download seems to be a 32 bit version and will not run on 64 bit Windows 10. Since this is targeting the packager for Java 11, should it be 64 bit, or could you provide a 64 bit version (such as Runner64)?
 

tchart

Well-Known Member
Licensed User
Longtime User
@OliverA sorry that URL has been moved, I will update it.

The C# compiler (csc) defaults to "anycpu" for the platform which means "... runs as a 64-bit process whenever possible and falls back to 32-bit when only that mode is available..."

The current build works fine on 64 bit Windows (thats what I use every day).

Docs;

If you specifically want a 64 bit only version I can add an additional build batch file if that would help you.
 

OliverA

Expert
Licensed User
Longtime User
The current build works fine on 64 bit Windows (thats what I use every day).
My Win10Pro system at work complained, would not run it and said to ask the author for a 64bit version. Who knows. Thanks for the extra step, I'll test it tomorrow
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…