import com.sun.image.codec.jpeg.*

I have a Java program when I compile it I get the following error

[javac] ...\MyClass.java:33: package com.sun.image.codec.jpeg does not exist
[javac] import com.sun.image.codec.jpeg.*;
[javac] ^

what can I do ?

What is the correct way of writing an image file now that the com.sun package is deprecated.

Answers


Why are you using classes in the package com.sun.image.codec.jpeg? You are not supposed to use those classes directly: Why Developers Should Not Write Programs That Call 'sun' Packages.

What does your program do? Does it just try to read or write a JPG image? That's very easy with the ImageIO API. See this tutorial: Writing/Saving an Image.

Addition - 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.


I had this problem when compiling with JDK 7. Strange enough Eclipse did not show this error, only javac did. The answer can be found in this Stackoverflow answer: javac uses a special symbol table that does not include all Sun-proprietary classes, and suppliying -XDignore.symbol.file makes the problem go away.

Of course, a much better solution is to rewrite the code without using the proprietary classes, but to support JDK 7 quickly, this option works.


In general, try not to use classes from "sun." or "com.sun." packages, as this packages are considered implementation details, and are not part of the Java API.

They can cause problems when moving to new versions of Java because there is no backwards compatibility guarantee. Similarly, they can cause problems when moving to a different Java vendor, such as OpenJDK.

Such classes are almost always wrapped by Java API classes that should be used instead.

See: https://sonarcloud.io/organizations/default/rules?languages=java&open=squid%3AS1191&q=sun


Which JDK are you using? I think that this package is not a requirement and will only be available in Sun's JDK. This discussion explains.

You may be able to download the jar file and include it on your path file separately if you really want to use it though.

According to docs:

Note that the classes in the com.sun.image.codec.jpeg package are not part of the core Java APIs. They are a part of Sun's JDK and JRE distributions. Although other licensees may choose to distribute these classes, developers cannot depend on their availability in non-Sun implementations. We expect that equivalent functionality will eventually be available in a core API or standard extension.


Looks like you are using something that has been replaced. Maybe you are on Java 7?

Here is something that seems to describe this, and where to go to find it's proper replacement.


Need Your Help

ASP.NET MVC3 - textarea with @Html.EditorFor

asp.net-mvc-3

I have ASP.NET MVC3 app and I have also form for add news. When VS2010 created default view I have only text inputs for string data, but I want to have textarea for news text. How I can do it with ...

how do I create a new EKCalendar on iOS device?

iphone objective-c ios ipad

I have an app where I want to schedule some events. So I want to create a new calendar for my app if it does not yet exist and if it does reference that when adding new events.