0

I would like wrap an import-statement with a try-catch-block. How can I do this in Java?

In more detail, I want to import

import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;

However, this class is only available if the JDK runs on Windows. It is not available when I build the same come on Linux (e. g. in Jenkins, see OpenJDK 11: class not found error com.sun.java.swing.plaf.windows.WindowsLookAndFeel (linux)).

So, I would like to do something like

try { 
    import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
} catch(Exception e) {
    ...
}

In Python, it is possilbe to wrap imports with a try-block. Is there a similar solution in Java?

JavAlex
  • 4,974
  • 1
  • 12
  • 14

0 Answers0