B4J Question [SOLVED] Error Running Stand Alone App IllegalAccessException com.sun.proxy.jdk.proxy2.$Proxy3

MrKim

Well-Known Member
Licensed User
Longtime User
The full message is below.

B4X:
java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject (in module b4j) cannot access class com.sun.proxy.jdk.proxy2.$Proxy3 (in module jdk.proxy2) because module jdk.proxy2 does not export com.sun.proxy.jdk.proxy2 to module b4j
        at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Unknown Source)
        at java.base/java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at b4j/anywheresoftware.b4j.object.JavaObject.RunMethod(Unknown Source)
        at b4j/com.stevel05.draganddrop.dadmod._setforegroundwindow(Unknown Source)
        at b4j/com.stevel05.draganddrop.dadmod._openjobinsk2010(Unknown Source)
        at b4j/com.stevel05.draganddrop.main._jobnumlbl_mouseclicked(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at b4j/anywheresoftware.b4a.BA.raiseEvent2(Unknown Source)
        at b4j/anywheresoftware.b4a.BA.raiseEvent(Unknown Source)
        at b4j/anywheresoftware.b4j.objects.NodeWrapper$1.handle(Unknown Source)
        at b4j/anywheresoftware.b4j.objects.NodeWrapper$1.handle(Unknown Source)
        at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
        at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
        at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
        at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
        at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
        at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
        at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
        at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
        at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
        at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
        at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
        at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
        at javafx.base/javafx.event.Event.fireEvent(Unknown Source)
        at javafx.graphics/javafx.scene.Scene$ClickGenerator.postProcess(Unknown Source)
        at javafx.graphics/javafx.scene.Scene$ClickGenerator.access$8200(Unknown Source)
        at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Unknown Source)
        at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1200(Unknown Source)
        at javafx.graphics/javafx.scene.Scene.processMouseEvent(Unknown Source)
        at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(Unknown Source)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.View.notifyMouse(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)

Here is the code (I am aware it has other issues ? ):
B4X:
Sub SetForegroundWindow(Title As String, JustFind As Boolean) As Boolean
Try
 
Dim WU As JavaObject
WU.InitializeStatic("com.sun.jna.platform.WindowUtils")
Dim user32 As JavaObject
user32 = user32.InitializeStatic("com.sun.jna.platform.win32.User32").GetField("INSTANCE")
Dim L As List = WU.RunMethod("getAllWindows",Array(False))
For Each JO As JavaObject In L
    Dim t As String = JO.RunMethod("getTitle",Null)
    If t.EqualsIgnoreCase(Title) Then
        If JustFind Then
            Return True
        Else
            Dim hwnd As Object = JO.RunMethod("getHWND", Null)
            user32.RunMethod("SetForegroundWindow", Array(hwnd))
            user32.RunMethod("SetFocus", Array(hwnd))
            user32.RunMethod("ShowWindow", Array(hwnd, 9))'SW_RESTORE
            Return False
        End If
    End If
Next
Return False
Log("Window not found")
Catch
    Main.Msgbox.Show(LastException, "SetForegroundWindow")
End Try
End Sub
It is a slightly modified version of Erel's code Here

I am guessing it has to do with needing to add
B4X:
    #AdditionalJar: jna-5.0.0
    #AdditionalJar: jna-platform-5.0.0
using #PackagerProperty:
or #CustomBuildAction:

But I am not sure how.

I tried
B4X:
    #PackagerProperty: IncludedModules = jna-5.0.0
    #PackagerProperty: IncludedModules = jna-platform-5.0.0
but it did not work. Gave this error:

B4X:
B4JPackager11 Version 1.40
.
.
.
Explicitly excluded modules: [javafx.web]
Included modules: [jna-5.0.0, jna-platform-5.0.0, java.base, java.datatransfer, java.desktop, java.logging, java.naming, java.security.jgss, java.sql, java.transaction.xa, java.xml, javafx.base, javafx.controls, javafx.fxml, javafx.graphics, javafx.media, javafx.swing, java.scripting, jdk.unsupported, jdk.unsupported.desktop, jdk.jsobject, jdk.xml.dom]
Running: C:\Java\jdk-11.0.1\bin\javac
.
module-info.java:2: error: ';' expected
requires jna-5.0.0;
            ^
1 error
It runs fine in Debug mode.
Any help greatly appreciated.
 

Attachments

  • 1654759562988.png
    1654759562988.png
    17.6 KB · Views: 333
Last edited:
Solution
I see it too. It is related to JNA using a special dynamic proxy that can no longer be accessed with reflection when the app is modularized.

You will need to use inline Java instead:
B4X:
Sub SetForegroundWindow(Title As String, JustFind As Boolean) As Boolean
    Return Me.As(JavaObject).RunMethod("SetForegroundWindow", Array(Title, JustFind))
End Sub

#if Java
import com.sun.jna.platform.win32.*;
public static boolean SetForegroundWindow(String title, boolean justFind) {
    User32 user32 = com.sun.jna.platform.win32.User32.INSTANCE;
    for (com.sun.jna.platform.DesktopWindow s : com.sun.jna.platform.WindowUtils.getAllWindows(false)) {
        String t = s.getTitle();
        if (t.toLowerCase().equals(title.toLowerCase())) {...

Magma

Expert
Licensed User
Longtime User
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
..at Main

B4X:
    #VirtualMachineArgs: -Xms1024m -Xmx3072m 'hmmm may be need that too

    #AdditionalJar: jna-5.2.0    'i have 5.2.0
    #AdditionalJar: jna-platform-5.2.0

#MergeLibraries: true 'I am using that too..
Well, I added the two lines you show, #VirtualMachineArgs: -Xms1024m -Xmx3072m and #MergeLibraries: true

but it made no difference
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Try putting them both on 1 line:

B4X:
 #PackagerProperty: IncludedModules = jna-5.0.0, jna-platform-5.0.0
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Try putting them both on 1 line:

B4X:
 #PackagerProperty: IncludedModules = jna-5.0.0, jna-platform-5.0.0
same error:
B4X:
B4JPackager11 Version 1.40
Running: C:\Java\jdk-11.0.1\bin\javac
.
.
.
Running: C:\Java\jdk-11.0.1\bin\javac
.
module-info.java:2: error: ';' expected
requires jna-5.2.0;
            ^
1 error

Where do you have the files?
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
...hmmm...

I have them into:

C:\Program Files\Anywhere Software\B4J\Libraries

Caution... if you had them last time into "Program Files x86" Anywhere Software\B4J\Libraries - you must move them (if b4j updated at last version) ... because now, b4j is 64bit...
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
If you check - the location - of files... and not fix that...

...Something else came in mind... jna is a way to connect with .net framework and kernel...

* What Windows version do you have ?
* Also what .NET Framework version (may be need an update) ?

but from the other hand your code run in debug...
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
...hmmm...

I have them into:



Caution... if you had them last time into "Program Files x86" Anywhere Software\B4J\Libraries - you must move them (if b4j updated at last version) ... because now, b4j is 64bit...
Been awhile -I was sick.
Files are in
B4X:
C:\Program Files (x86)\Anywhere Software\B4J\Libraries
using version
B4X:
9.30
Interestingly, since I am using the MS jdbc driver I added the line:
B4X:
#PackagerProperty: IncludedModules = mssql-jdbc-7.2.2.jre11
and I get EXACTLY the same error but relating to the jdbc file.
B4X:
B4JPackager11 Version 1.40
.
.
Running: C:\Java\jdk-11.0.1\bin\javac
.
module-info.java:2: error: ';' expected
requires mssql-jdbc-7.2.2.jre11;
              ^
1 error
this file is also in
B4X:
C:\Program Files (x86)\Anywhere Software\B4J\Libraries
and does NOT seem to require a
B4X:
#PackagerProperty
line.
I am at a loss.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
If you check - the location - of files... and not fix that...

...Something else came in mind... jna is a way to connect with .net framework and kernel...

* What Windows version do you have ?
* Also what .NET Framework version (may be need an update) ?

but from the other hand your code run in debug...
Win 10 with latest updates.
1655249203219.png


1655249141210.png
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
#PackagerProperty: IncludedModules = mssql-jdbc-7.2.2.jre11

module-info.java:2: error: ';' expected
requires mssql-jdbc-7.2.2.jre11;
^
needs ";" at the end ?
B4X:
#PackagerProperty: IncludedModules = mssql-jdbc-7.2.2.jre11;
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
First step is to run run_debug.bat and post the error message as text.
Done, I added it to the first post. I wasn't getting anything, Didn't realize you had to leave the Log(Lastexception) statements in.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
needs ";" at the end ?
B4X:
#PackagerProperty: IncludedModules = mssql-jdbc-7.2.2.jre11;
Thanks, tried that. You just get the same error with TWO semi-colons on the end.
B4X:
requires mssql-jdbc-7.2.2.jre11;;
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Try to add:
B4X:
#PackagerProperty: VMArgs = --add-opens jdk.proxy2/com.sun.proxy.jdk.proxy2=b4j
As always, thanks for your help Erel. It did shorten the message.
B4X:
C:\ProgramData\ShopKeeper2010\SkSchedule>cd bin

C:\ProgramData\ShopKeeper2010\SkSchedule\bin>java.exe @release_java_modules.txt --add-opens jdk.proxy2/com.sun.proxy.jdk.proxy2=b4j -m b4j/com.stevel05.draganddrop.main
WARNING: Unknown module: jdk.proxy2 specified to --add-opens
(IllegalAccessException) java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject (in module b4j) cannot access class com.sun.proxy.jdk.proxy2.$Proxy3 (in module jdk.proxy2) because module jdk.proxy2 does not export com.sun.proxy.jdk.proxy2 to module b4j
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Please upload a small project that reproduces it.
Here it is. Works fine in design, fails as stand alone exe.
Requires notepad to be open with the title "Untitled - NotePad" to fail.
Zipped executable is HERE. I think link will work. Dropbox link.
 

Attachments

  • TestOfjnaFailure.zip
    3.3 KB · Views: 177
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I see it too. It is related to JNA using a special dynamic proxy that can no longer be accessed with reflection when the app is modularized.

You will need to use inline Java instead:
B4X:
Sub SetForegroundWindow(Title As String, JustFind As Boolean) As Boolean
    Return Me.As(JavaObject).RunMethod("SetForegroundWindow", Array(Title, JustFind))
End Sub

#if Java
import com.sun.jna.platform.win32.*;
public static boolean SetForegroundWindow(String title, boolean justFind) {
    User32 user32 = com.sun.jna.platform.win32.User32.INSTANCE;
    for (com.sun.jna.platform.DesktopWindow s : com.sun.jna.platform.WindowUtils.getAllWindows(false)) {
        String t = s.getTitle();
        if (t.toLowerCase().equals(title.toLowerCase())) {
            if (!justFind) {
                user32.SetForegroundWindow(s.getHWND());
                user32.SetFocus(s.getHWND());
                user32.ShowWindow(s.getHWND(), 9);
            }
            return true;
        }
        
    }
    return false;
}
#End If
 
Upvote 0
Solution
Top