Search code examples
javamacosjar

cannot access class com.apple.eawt.Application (in module java.desktop) because module java.desktop does not export com.apple.eawt to unnamed module


I'm trying to execute a JAR file called fakeSMPTServer on MacOS Monterrey with OpenJDK with the command:

java -jar fakeSMTP-2.0.jar

And I get the error:

03 Apr 2023 10:04:51 ERROR com.nilhcem.fakesmtp.core.exception.UncaughtExceptionHandler - 
java.lang.IllegalAccessError: class com.nilhcem.fakesmtp.FakeSMTP$1 (in unnamed module @0x5db54e92) cannot access class com.apple.eawt.Application (in module java.desktop) because module java.desktop does not export com.apple.eawt to unnamed module @0x5db54e92
    at com.nilhcem.fakesmtp.FakeSMTP$1.run(FakeSMTP.java:80) ~[fakeSMTP-2.0.jar:na]
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318) ~[na:na]
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773) ~[na:na]
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720) ~[na:na]
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714) ~[na:na]
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) ~[na:na]
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) ~[na:na]
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742) ~[na:na]
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) ~[na:na]
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) ~[na:na]
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) ~[na:na]
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) ~[na:na]
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) ~[na:na]
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90) ~[na:na]

The following is the output of java --version:

openjdk 19.0.2 2023-01-17
OpenJDK Runtime Environment Homebrew (build 19.0.2)
OpenJDK 64-Bit Server VM Homebrew (build 19.0.2, mixed mode, sharing)

Solution

  • This is a known issue [1] [2] with later versions of Java.

    The solution is to allow com.apple.eawt to be exported. This can be done by adjusting the launch command to the following:

    java --add-exports java.desktop/com.apple.eawt=ALL-UNNAMED -jar fakeSMTP-2.0.jar