0

I am trying to migrate a project from JDK8 to JDK11, the issue is that most of the things are no longer part of JDK11 as they used to be in JDK8. There are some separated jars that I had to add manually due removal of those packages from JDK11, but one issue remains. The import com.sun.imageio.plugins.jpeg.JPEGImageReader; is no longer part of JDK11 and I am not able to find proper replacement or dependency in order to provide to my code so it can work as it used to.

I've visited docs https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/package-summary.html but they do not seem like a proper replacement

InputStream iccProfileStream = JPEGImageReader.class.getResourceAsStream("/ISOcoated_v2_300_eci.icc");

//the JPEGImageReader is completely red due missing jar that was removed from JDK11

cmykProfile = ICC_Profile.getInstance(iccProfileStream);
iccProfileStream.close();

Code should compile as it used to do on JDK8 but instead, it keeps popping an error "package com.sun.imageio.jpeg is not visible (package com.sun.imageio.plugins.jpeg is declared in module java.desktop, which does not export it )"

zawarudo
  • 1,907
  • 2
  • 10
  • 20
  • 1
    Does this help? https://stackoverflow.com/questions/2999528/is-there-a-100-java-alternative-to-imageio-for-reading-jpeg-files – GhostCat Sep 17 '19 at 12:52
  • javax.imagio was introduced in Java SE 1.4 (2002) so there shouldn't be a need to use the non-standard com.sun.imagio.plugins.jpeg API package anymore. This was flagged in the JDK 9 release notes here: https://www.oracle.com/technetwork/java/javase/9-removed-features-3745614.html#JDK-8038838 – Alan Bateman Sep 17 '19 at 13:56

1 Answers1

1

It doesn't seem that you even need that class, at least based on the code you're showing.

Instead of JPEGImageReader.class.getResourceAsStream(.., you can use any Class object as long as it's in the suitable classloading context. The getResourceAsStream method exists in the Class class.

Replace it with getClass().getResourceAsStream(.. and that part of the code will work just fine.

Kayaman
  • 72,141
  • 5
  • 83
  • 121
  • The thing about having a big project, and having something to remove, is extremely frightening at least for me. I will try what you suggested. Thank you so much Kayaman. – zawarudo Sep 17 '19 at 13:03
  • @Milosh the problem here is using the plugin class directly, although maybe it was necessary (in some other part). – Kayaman Sep 17 '19 at 13:06
  • Yes, that is the main issue with big projects, you never know what you can stop using. Thanks. – zawarudo Sep 17 '19 at 13:11