B4J Question Solved - java.lang.ClassNotFoundException ManagementFactory when Built Standalone

swChef

Active Member
Licensed User
Longtime User
I reproduced the problem I have in a minimal project. Create a new default B4XPage app, and change Button1_Click as follows:
B4X:
Private Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X " & TryThisInstead)
End Sub

Sub TryThisInstead As String
    Dim jo As JavaObject
    Log("initializing MF")
    jo=jo.InitializeStatic("java.lang.management.ManagementFactory")
    Return ""
End Sub
This is a stripped down test. In my (larger) application, and when creating this minimal app, it is the first step, followed by getRuntimeMXBean, then getName, to get the PID.
This is failing after Build Standalone Package trying to run the .exe (in this example, upon clicking the button), but works when run from the IDE.
I've been using jdk 14 and also tried 11, same issue.

I'm guessing there is perhaps a dll or additional jar to include, but haven't discovered that yet. Has someone run across this and has the solution?

run_debug.bat shows the error while running the built .exe.
B4X:
initializing MF
b4xmainpage._trythisinstead (java line: -1)
java.lang.ClassNotFoundException: java$lang$management$ManagementFactory
        at b4j/anywheresoftware.b4j.object.JavaObject.getCorrectClassName(Unknown Source)
        at b4j/anywheresoftware.b4j.object.JavaObject.InitializeStatic(Unknown Source)
        at b4j/b4j.example.b4xmainpage._trythisinstead(Unknown Source)
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
sounds like an issue of the packager:

try with packagerProperty: include = java.lang.management
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Add this to project attributes region ( you may not need the second line if you don't need remote connect )
B4X:
    #PackagerProperty: IncludedModules=java.management
    #PackagerProperty: IncludedModules=java.management.rmi
 
Upvote 0

swChef

Active Member
Licensed User
Longtime User
Add this to project attributes region ( you may not need the second line if you don't need remote connect )
B4X:
    #PackagerProperty: IncludedModules=java.management
    #PackagerProperty: IncludedModules=java.management.rmi

Thank you for the info. Using that to search I found another thread on this topic. Not sure how I didn't find that yesterday, other than the typos and '.lang.' included in my search. The thread has some information on how to determine the module to include.
https://www.b4x.com/android/forum/threads/solved-missing-java-class-in-a-packaged-exe.118705/?amp=1
 
Upvote 0
Top