B4J Question [Solved] Missing Java class in a packaged EXE

DavideV

Active Member
Licensed User
Longtime User
Hello Devs,
I'm working on a simple B4J app that runs fine from the ide, B4J V8.30.
When the app is packaged to an EXE using the internal packager (Project->build stndalone package), it crashes on a specific sub that make use of javaobject:

B4X:
ub getAppPid As String
    Dim jo As JavaObject
    jo.InitializeStatic("java.lang.management.ManagementFactory")
    Dim pid As String = jo.RunMethodJO("getRuntimeMXBean",Null).RunMethod("getName",Null)
    pid= pid.SubString2(0,pid.IndexOf("@"))
    Log("[PB] this pid : " & pid)
    Return pid
End Sub

It looks like the java.lang.management.ManagementFactory class is missing from the packaged app.
To record the error, I used a messagebox, so here is the screenshot:

error.png


As I said, it doesn't happen running from the ide.
I'm sure there will be different approaches to get the app PID, but I think it is useful to report the error.

Cheers
Davide
 

Daestrum

Expert
Licensed User
Longtime User
Assuming you are using java 11+ you will need to add
B4X:
    #PackagerProperty: IncludedModules = java.management
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Just in-case anyone else gets a similar message this is how to find which module you need to include
Using the above as an example

1, copy the missing class name -> java.lang.management.ManagementFactory
2, Google it adding api java 11 -> java.lang.management.ManagementFactory api java 11
3. Look at result from docs.oracle.api. ... -> ManagementFactory(Java SE 11 & JDK 11)
4, Open that page
5, At the top of the page will be ->
Module java.management
6, This is the name of the module you need to include. -> #PackagerProperty: IncludedModules = java.management

Hope it helps.
 
Last edited:
Upvote 0
Top