Issue
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 )"
Solution
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.
Answered By - Kayaman
Answer Checked By - Katrina (JavaFixing Volunteer)