进口com.sun.image.codec.jpeg。*

时间:2022-04-03 17:20:07

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

我有一个Java程序,当我编译它时,我得到以下错误

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

写一个图像文件的正确方法是什么?阳光包被弃用。

4 个解决方案

#1


30  

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.

为什么要在com.sun.image.codec.jpeg包中使用类?您不应该直接使用这些类:为什么开发人员不应该编写调用“sun”包的程序。

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.

你的程序是做什么的?它只是尝试读或写一个JPG图像吗?使用ImageIO API非常容易。参见本教程:编写/保存映像。

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.

另外,在Java SE 7和JDK 7兼容性指南中提到的Java 7中已经删除了包com.sun.image.codec.jpeg。

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

概要:非标准com.sun.image.codec.jpeg包已经退役

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.

JPEG包是在JDK 1.2(1998年12月)中添加的,作为控制JPEG格式图像文件的加载和保存的非标准方法。这个包从来都不是平台规范的一部分,它已经从Java SE 7版本中删除了。Java映像I/O API作为标准API添加到JDK 1.4版本中,从而消除了com.sun.image.codec.jpeg包的需要。

#2


49  

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

我在使用JDK 7编译时遇到了这个问题。奇怪的是,Eclipse没有显示这个错误,只有javac显示。答案可以在这个*答案中找到:javac使用一个特殊的符号表,它不包括所有sun专有的类,以及suppliying -XDignore.symbol。文件使问题消失。

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.

当然,更好的解决方案是重写代码而不使用私有类,但是要快速支持JDK 7,这个选项可以工作。

#3


1  

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.

您正在使用哪个JDK ?我认为这个包不是必需的,只能在Sun的JDK中使用。这个讨论解释道。

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.

您可以下载jar文件,并将它单独包含在您的路径文件中,如果您真的想使用它的话。

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.

注意,com.sun.image. cox .jpeg包中的类不是核心Java api的一部分。它们是Sun的JDK和JRE发行版的一部分。虽然其他被许可方可以选择分发这些类,但是开发人员不能依赖于它们在非sun实现中的可用性。我们期望在核心API或标准扩展中最终可以使用相同的功能。

#4


1  

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

看起来你用的东西已经被替换了。也许您正在使用Java 7?

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

这里有一些描述,以及去哪里找到合适的替代品。

#1


30  

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.

为什么要在com.sun.image.codec.jpeg包中使用类?您不应该直接使用这些类:为什么开发人员不应该编写调用“sun”包的程序。

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.

你的程序是做什么的?它只是尝试读或写一个JPG图像吗?使用ImageIO API非常容易。参见本教程:编写/保存映像。

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.

另外,在Java SE 7和JDK 7兼容性指南中提到的Java 7中已经删除了包com.sun.image.codec.jpeg。

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

概要:非标准com.sun.image.codec.jpeg包已经退役

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.

JPEG包是在JDK 1.2(1998年12月)中添加的,作为控制JPEG格式图像文件的加载和保存的非标准方法。这个包从来都不是平台规范的一部分,它已经从Java SE 7版本中删除了。Java映像I/O API作为标准API添加到JDK 1.4版本中,从而消除了com.sun.image.codec.jpeg包的需要。

#2


49  

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

我在使用JDK 7编译时遇到了这个问题。奇怪的是,Eclipse没有显示这个错误,只有javac显示。答案可以在这个*答案中找到:javac使用一个特殊的符号表,它不包括所有sun专有的类,以及suppliying -XDignore.symbol。文件使问题消失。

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.

当然,更好的解决方案是重写代码而不使用私有类,但是要快速支持JDK 7,这个选项可以工作。

#3


1  

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.

您正在使用哪个JDK ?我认为这个包不是必需的,只能在Sun的JDK中使用。这个讨论解释道。

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.

您可以下载jar文件,并将它单独包含在您的路径文件中,如果您真的想使用它的话。

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.

注意,com.sun.image. cox .jpeg包中的类不是核心Java api的一部分。它们是Sun的JDK和JRE发行版的一部分。虽然其他被许可方可以选择分发这些类,但是开发人员不能依赖于它们在非sun实现中的可用性。我们期望在核心API或标准扩展中最终可以使用相同的功能。

#4


1  

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

看起来你用的东西已经被替换了。也许您正在使用Java 7?

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

这里有一些描述,以及去哪里找到合适的替代品。