Java 导入 com.sun.image.codec.jpeg.*
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1906673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
import com.sun.image.codec.jpeg.*
提问by silverkid
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.
现在不推荐使用 com.sun 包,写入图像文件的正确方法是什么。
采纳答案by Jesper
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' 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.
你的程序是做什么的?它只是尝试读取或写入 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 兼容性指南中com.sun.image.codec.jpeg
所述,该包已在 Java 7 中删除。
Synopsis:The Non-standard
com.sun.image.codec.jpeg
Package is RetiredDescription: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 thecom.sun.image.codec.jpeg
package.
简介:非标
com.sun.image.codec.jpeg
包退市描述:该
com.sun.image.codec.jpeg
包是在 JDK 1.2(1998 年 12 月)中添加的,作为控制 JPEG 格式图像文件加载和保存的非标准方式。这个包从来不是平台规范的一部分,它已从 Java SE 7 版本中删除。Java Image I/O API 作为标准 API 添加到 JDK 1.4 版本中,并且不再需要该com.sun.image.codec.jpeg
包。
回答by Vincent Ramdhanie
Which JDK are you using? I think that this package is not a requirement and will only be available in Sun's JDK. This discussionexplains.
你用的是哪个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.codec.jpeg 包中的类不是核心 Java API 的一部分。它们是 Sun 的 JDK 和 JRE 发行版的一部分。尽管其他被许可方可能会选择分发这些类,但开发人员不能依赖于它们在非 Sun 实现中的可用性。我们预计最终将在核心 API 或标准扩展中提供等效功能。
回答by Francis Upton IV
回答by mainzelM
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.
我在用 JDK 7 编译时遇到了这个问题。奇怪的是 Eclipse 没有显示这个错误,只有 javac 显示了。答案可以在这个 Stackoverflow 答案中找到:javac 使用了一个特殊的符号表,它不包括所有 Sun 专有的类,并且提供-XDignore.symbol.file
使问题消失。
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,此选项有效。
回答by Diego Turiso
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.
通常,尽量不要使用来自“sun. ”或“com.sun.”包的类,因为这些包被视为实现细节,而不是 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.
在迁移到新版本的 Java 时,它们可能会导致问题,因为没有向后兼容性保证。同样,当迁移到不同的 Java 供应商(例如 OpenJDK)时,它们可能会导致问题。
Such classes are almost always wrapped by Java API classes that should be used instead.
这些类几乎总是由应该使用的 Java API 类包装。
See: https://sonarcloud.io/organizations/default/rules?languages=java&open=squid%3AS1191&q=sun
参见:https: //sonarcloud.io/organizations/default/rules?languages=java&open=squid%3AS1191&q=sun