How to resolve package com.sun.image.codec.jpeg does not exist?

Sometimes the java project (usually a lower version of Java (1.6 or lower)) results in the following compilation error:-

INFO] Compiling 106 source files to /Users/JavaProject/src/java/web/target/classes [INFO] ————————————————————- [ERROR] COMPILATION ERROR : [INFO] ————————————————————- [ERROR] /Users/JavaProject//src/java/web/main/java/net/esi/ppc/presentation/service/CaptchaImageGenerator.java:[24,31] error: package com.sun.image.codec.jpeg does not exist [ERROR] /Users/JavaProject//src/java/web/main/java/net/esi/ppc/presentation/service/CaptchaImageGenerator.java:[25,31] error: package com.sun.image.codec.jpeg does not exist

To resolve this issue you can add the following in the pom.xml

<compilerArgument>

            -XDignore.symbol.file

</compilerArgument>

It’s basically an argument for the Java compiler. Also, adding the arguments “-XDignore.symbol.file” will depend on the build tool.

A much better solution is to rewrite the code without using the proprietary classes.Because you are not supposed to directly use the classes under the package com.sun.image.codec.jpeg

But if you have a legacy code which you can’t change, then this is the solution.

You can read the following post for more information :-https://www.oracle.com/technetwork/java/faq-sun-packages-142232.html

The package com.sun.image.codec.jpeg has been removed in Java 7 as mentioned in the Java SE 7 and JDK 7 Compatibility Guide.

Synopsis: The Non-standard com.sun.image.codec.jpeg Package is Retired

Description: The com.sun.image.codec.jpeg package was added in JDK 1.2 (Dec 1998) as a non-standard way of controlling the loading and saving of JPEG format image files. This package was never part of the platform specification and it has been removed from the Java SE 7 release. The Java Image I/O API was added to the JDK 1.4 release as a standard API and eliminated the need for the com.sun.image.codec.jpeg package.

Let me know if this solution worked for you .Happy Coding guys an gals 🙂

Published by Anna

Just a simple girl who loves to code. .I am primarily a Java developer by profession and I am here to share my love for coding with you all I hope you enjoy reading my blog. Happy Coding Guys :-)

Leave a comment

Your email address will not be published. Required fields are marked *