B4J Question 3rd party java launchers - experiences please

JackKirk

Well-Known Member
Licensed User
Longtime User
My project currently employs 10 B4J apps sitting in an AWS EC2 instance.

Early on I discovered a little management issue - if you just launch the B4J *.jar files directly the resulting instances all appear as "Java (TM) Platform SE binary" in the Windows Task Manager - which makes it a little confusing when you muck around at this level.

So I've been using a 3rd party java launcher - effectively each jar is wrapped in a *.exe with name of your choice - you launch the *.exe instead of the *.jar and Task Manager shows the individual names - bliss.

Or so I thought.

I've been using winrun4j because it had an ultra simple *.ini configuration file and this has worked fine for all the batch B4J apps.

I've now written an interactive B4J app with main and child forms and am finding winrun4j is doing some annoying little things with the form layouts - I know it is winrun4j because if I run the B4J app from its *.jar everything works as it is supposed to.

I've looked at launch4j but am put off by the huge configuration effort that seems to be involved - no desire to go thru that then discover I still have the same problems as winrun4j.

So I'm asking (begging...) for any useful experiences others may have had in this area.

Thanks in anticipation...
 

udg

Expert
Licensed User
Longtime User
Hi,
what I do is to use the following few lines of code at AppStart beginning
B4X:
'write PID on thefilesystem
Dim jo As JavaObject
jo.InitializeStatic("java.lang.management.ManagementFactory")
Dim pid As String = jo.RunMethodJO("getRuntimeMXBean",Null).RunMethod("getName",Null)
File.WriteString(File.DirApp,"varsvc1pid.txt","VarSvc1: "& pid.SubString2(0,pid.IndexOf("@")))
where varsvc1pid.txt is the name of the text file showing the PID for the current B4J server app, named after the program name (varsvc1)
and VarSvc1: is a "label" to again identify the program to which the PID is associated (named after the program name, as above).

udg
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Erel, udg,

Thanks for your replies...
It is very simple to use launch4j: https://www.b4x.com/android/forum/threads/35863/#content
I'm not familiar with any issue related to this tool.
Erel, I bit the bullet and had a go at launch4j using your tutorial which lifts a lot of the fog around configuration.

I can generate a named .exe but when I launch it it generates 2 entries in Windows Task Manager - 1 is named as per the .exe and the other is the underlying jar (which still appears as "Java (TM) Platform SE binary").

I can end the .exe task in Windows Task Manager and the .jar task will remain running.

I have tried everything I can think of in the launch4j configuration GUI to try and insert the jar inside the .exe but nothing - any suggestions?
There is another option (probably better). Run the jars and use 'jps' to identify the java processes.
Erel, I actually use the unique task names outside of Task Manager - i.e. a great little utility called Restart On Crash - so this is not a solution.
Hi,
what I do is to use the following few lines of code at AppStart beginning
B4X:
'write PID on thefilesystem
Dim jo As JavaObject
jo.InitializeStatic("java.lang.management.ManagementFactory")
Dim pid As String = jo.RunMethodJO("getRuntimeMXBean",Null).RunMethod("getName",Null)
File.WriteString(File.DirApp,"varsvc1pid.txt","VarSvc1: "& pid.SubString2(0,pid.IndexOf("@")))
where varsvc1pid.txt is the name of the text file showing the PID for the current B4J server app, named after the program name (varsvc1)
and VarSvc1: is a "label" to again identify the program to which the PID is associated (named after the program name, as above).

udg
udg - similar comments to my last one to Erel.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Erel, I actually use the unique task names outside of Task Manager - i.e. a great little utility called Restart On Crash - so this is not a solution.
I think that this is the best solution. You can create a small non-ui app that checks whether your processes running and start them if needed.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
I think that this is the best solution. You can create a small non-ui app that checks whether your processes running and start them if needed.
Erel, not quite sure I follow this comment - are you saying ROC is a good solution or are you saying I should write an app that basically replicates it?
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
I'm not familiar with ROC. I say that it should be quite simple to create an app that manages your other apps and starts them if needed.
Quite possibly so but I've used ROC for years to enhance stability of various unattended Windows systems - it is extremely simple and solid as a rock so I don't really see much point

One of the 10 B4J apps I mention above monitors the ROC log (another nifty little feature) and sends me an SMS if anything falls over and gets restarted (which is extremely rare).
 
Upvote 0
Top