2

We have a desktop-based swing app running fine with Oracle JDK 1.8. After moving to OpenJDK 11 we got some not found exceptions for classes com.sun.java.swing.Painter, we resolved that by generating a bundled jar that contains some classes of com.sun.java.swing.Painter.java and some 4-5 classes and added it by

java --patch-module java.desktop=custombundle.jar -classpath path_of_jars starter_class*

Now everything works fine with AdoptOpenJDK11 or OpenJDK11 on Windows systems. But on Linux (Ubuntu-64 bits or any ARM-based Linux environments) we got another class not found/No class def exception related to class com.sun.java.swing.plaf.windows.WindowsLookAndFeel from the third-party libraries we used.

We can not remove the calls to com.sun.java.swing.plaf.windows.WindowsLookAndFeel because they are in 3rd party libs. The company providing the libs and also other forum sites suggest adding:

--add-exports java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED*
java --add-exports java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED --patch-module java.desktop=custombundle.jar -classpath path_of_jars starter_class*

but after adding this get a warning such as

WARNING: package com.sun.java.swing.plaf.windows not in java.desktop

and we got still the class not found exceptions for com.sun.java.swing.plaf.windows.WindowsLookAndFeel

I tried java.desktop/com.sun.java.swing.plaf.gtk instead of java.desktop/com.sun.java.swing.plaf.windows, the warning disappeared but still not working. Any suggestions?

Adopt OpenJDK version: latest (11.0.8.10)

Ubuntu: 20.04 (recent)

Note: Swing Issue on Java 10 did not help

Ronak Jain
  • 3,073
  • 1
  • 11
  • 17
benchpresser
  • 2,171
  • 2
  • 23
  • 41
  • 2
    The classes for the WindowsLookAndFeel are only included in Windows versions of the Jdk. – weisj Jul 20 '20 at 08:56
  • yes i saw them with --describe. so the solution must be the third party related upgrade etc. I think – benchpresser Jul 20 '20 at 09:23
  • 1
    *"But on linux (ubnutu-64 bits or any ARM based linux environments) we got another class not found/No class def exceptions related to com.sun.java.swing.plaf.windows.WindowsLookAndFeel from the third party libraries we used."* Why on Earth would Linux users want to see a Windows styled GUI?!? The safest bet is to use the ***native*** PLAF. Then users on all systems get to see a GUI which closely resembles (and in some case is indistinguishable from) the other apps on their OS. – Andrew Thompson Jul 20 '20 at 09:56
  • 1
    Hi, did you resolve this ? One of my third-party widget library is also relying on the WindowsLookAndFeel... – lvr123 Mar 15 '21 at 16:08
  • I generated a manual jar containins the classes, I know it is not the best solution and seems weird but worked – benchpresser May 08 '21 at 20:23
  • 1
    @AndrewThompson my Jenkins runs on linux, and should me able do build Windows apps… This is why on Earth. – Sxilderik Nov 05 '21 at 10:31
  • I wondered if there is any way to *try* to import `WindowsLookAndFeel` and to catch the error if this class does not to exist: https://stackoverflow.com/questions/71584986/wrap-an-import-statement-with-a-try-catch-block – JavAlex Mar 23 '22 at 09:50

0 Answers0