B4J Question How to handle multiple B4JPackager11 .exe modules to minimize disk usage

JackKirk

Well-Known Member
Licensed User
Longtime User
I have managed to get B4JPackager11 working but find I have a problem.

Each .exe package generated by B4JPackager11 is roughly 55MB

I run 16 B4J modules on AWS EC2 instances => 880MB total

I also run 7 B4J modules on small headless/legless field PCs => 380MB total

The disk space is not so much the problem (although it offends my sense of efficiency) however all these PCs are remote and periodically require updating - meaning upload times are a bit of a problem.

I have tried merging of the packages to cut out the duplicate files but can not find a way to do this so that all modules run correctly.

Any suggestions?
 

OliverA

Expert
Licensed User
Longtime User
What OS? JavaFX involved?
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Don't use the packager for this use case.

1. Copy OpenJDK 11, downloaded from this site.
2. Find release_java_modules.txt in B4J installation folder and copy it together with the jar.
3. Run the jar with:
B4X:
C:\java\jdk-11.0.1\bin\java.exe @release_java_modules.txt -p C:\java\jdk-11.0.1\javafx\lib -jar result.jar
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
This is how I run Jars produced by OpenJDK 11 or 14. For convenience I have set an environmental variable, OpenJdkPath, that points to the OpenJDK folder, in my case C:\jdk-14.0.1. This code is Basic4ppc and compiles to an exe. I put a copy of the exe in the same folder as the jar and rename it to whatever the jar is called and just run the exe.
 

Attachments

  • RunSelfNamedJarOpenJdk_v4.zip
    92.3 KB · Views: 188
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Don't use the packager for this use case.

1. Copy OpenJDK 11, downloaded from this site.
2. Find release_java_modules.txt in B4J installation folder and copy it together with the jar.
3. Run the jar with:
B4X:
C:\java\jdk-11.0.1\bin\java.exe @release_java_modules.txt -p C:\java\jdk-11.0.1\javafx\lib -jar result.jar
Erel, this is not a good solution.

Windows Task Manager shows the same name for all processes generated in this way i.e. "OpenJDK Platform binary".

In my production environment I use a small Windows management tool called "Restart On Crash" which monitors all designated running processes and restarts them in the (very rare) event they fall over - this relies on each process having a unique name - which is what the B4JPackager11 .exe files supply.

Prior to OpenJDK 11 I have used a third party tool called winrun4j to provide this ".exe transformation".

EDIT

Actually Windows Task Manager shows the name of all processes (created by either Erel's solution or via the B4JPackager11 .exe process) as "> OpenJDK Platform binary" with the window title exposed when you click the ">"
 
Last edited:
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
This is how I run Jars produced by OpenJDK 11 or 14. For convenience I have set an environmental variable, OpenJdkPath, that points to the OpenJDK folder, in my case C:\jdk-14.0.1. This code is Basic4ppc and compiles to an exe. I put a copy of the exe in the same folder as the jar and rename it to whatever the jar is called and just run the exe.
agraham, thanks for your interest in my issue.

As noted in the previous post to Erel I have been using a third party tool called winrun4j to provide this ".exe transformation" which sounds similar to what you are doing - I am going to explore your solution some more and get back to you - I might be a couple of days...
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
I am going to explore your solution some more and get back to you
agraham, unfortunately your solution has the same shortcoming as Erel's - the Restart On Crash tool can not distinguish between multiple running processes.
 
Last edited:
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
I have found a way to do this but am not happy with it:

field PC = AWS EC2 instance and headless/legless field PC

1. upload C:\java\jdk-11.0.1 from development PC to each field PC - a one time expense so this is OK
2. on development PC, for each production B4J module, just create its release jar - don't do the B4JPackager11 stuff - end up with MYB4JPGM.jar
3. upload each MYB4JPGM.jar to appropriate field PCs (say to D:\MYB4JPGM\MYB4JPGM.jar) - small so no problem
4. upload C:\Program Files (x86)\Anywhere Software\B4J\release_java_modules.txt from development PC to appropriate field PCs (say to D:\MYB4JPGM\release_java_modules.txt)
4. on each field PC, copy C:\java\jdk-11.0.1\java.exe to C:\java\jdk-11.0.1\MYB4JPGM.exe
5. on each field PC, launch MYB4JPGM with this launch command:

C:\java\jdk-11.0.1\bin\MYB4JPGM.exe @D:\MYB4JPGM\release_java_modules.txt -p C:\java\jdk-11.0.1\javafx\lib -jar D:\MYB4JPGM\MYB4JPGM.jar

this results in the Restart On Crash tool being able to see MYB4JPGM (actually the renamed/copied java.exe)

The thing I don't like about it is all the various MYB4JPGM.exe accumulating in C:\java\jdk-11.0.1\

I'd much prefer to have them in D:\MYB4JPGM with the like named jar - but I can not for the life of me work out how to modify the launch command to something like:

D:\MYB4JPGM\MYB4JPGM.exe @D:\MYB4JPGM\release_java_modules.txt -p C:\java\jdk-11.0.1\javafx\lib -jar D:\MYB4JPGM\MYB4JPGM.jar

I need a parameter to tell java.exe/MYB4JPGM.exe to look in C:\java\jdk-11.0.1\bin for all its bits.

Any suggestions?
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Erel,
Use the simple solution I posted above.

If you look closely at my last post I heavily plagiarise your suggestions in post #5
You can use Java built-in jps tool to monitor the Java processes.

I use the Restart On Crash (ROC) tool in a fully automated way with a monitoring and reporting mechanism on top of it. I have been using it for years in a number of projects - it is exceedingly stable and reliable. To do what you are suggesting it would appear I would have to discard it and write something similar to it and pass output from jps to it - I am loathe to do this.

It also seems a large effort when the alternative is to find a way to simply get the jar processes to divulge their "exe names" to ROC.

Is there a parameter on the java command that allows you to tell it to look in a particular folder for its "bits" - I have googled myself silly trying to find one.

PS while researching the jps tool I came across https://docs.oracle.com/javase/9/tools/jps.htm#JSWOR733 which states " This command is experimental and unsupported. "
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Is there a parameter on the java command that allows you to tell it to look in a particular folder for its "bits" - I have googled myself silly trying to find one.

Is there a non-trivial answer for this?
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
I don't know what is "bits".
I want to be able to run

D:\MYB4JPGM\MYB4JPGM.exe

where MYB4JPGM.exe is a renamed copy of C:\java\jdk-11.0.1\bin\java.exe

leaving all the remaining bits of java in C:\java\jdk-11.0.1
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I want to be able to run

D:\MYB4JPGM\MYB4JPGM.exe

where MYB4JPGM.exe is a renamed copy of C:\java\jdk-11.0.1\bin\java.exe

leaving all the remaining bits of java in C:\java\jdk-11.0.1
I've tried environment variables/registry settings and can't seem to get it going with manually installing a JDK. But, when using Amazon's Corretto installer for non-JavaFX applications or BellSoft's Liberica Full JRE (since technically don't need a JDK to execute .jar's) for JavaFX applications, something gets installed that allows you to accomplish what you are looking for. Since the installers work and my manual approach did not, I'm confident that I'm missing something, I just don't know what. At least there is a work around to your problem (as long as you have the ability to run installers on your headless field PC's).

Links:
Amazon Corretto: https://docs.aws.amazon.com/corretto/latest/corretto-11-ug/downloads-list.html
BellSoft's Liberica: https://bell-sw.com/pages/downloads/#/java-11-lts
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
@OliverA you could always look at my solution here;


It is based on Erels Packager code but modified to look for Java without putting it in the path.

It checks the current folder for a "runtime" folder (private JRE) and if that doesnt exist it looks for C:\Java (public JRE). The code is on GitHub.

This is what I use to avoid having multiple copies of the JDK.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top