我需要什么库才能在 Java 中访问这个 com.sun.image.codec.jpeg?

发布于 2024-12-27 03:21:38 字数 406 浏览 4 评论 0原文

我正在 java 中创建一个图像水印程序,并导入了以下内容:

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

但我收到一条错误消息:

访问限制:由于所需库C:\Program Files\Java\jre6\lib\rt.jar的限制,无法访问类型JPEGCodec

有人知道一种方法吗解决这个问题,或者我应该添加什么库才能访问该库以及在哪里找到该库?

I'm creating an image watermarking program in java and I imported the followings:

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

but I get an error that says:

Access restriction: The type JPEGCodec is not accesible due to restriction on required library C:\Program Files\Java\jre6\lib\rt.jar

Does someone know a way to solve this, or what library should I add in order to access that and where I find that library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

作业与我同在 2025-01-03 03:21:39

也许你的jre系统库是1.8

或eclipse:Project Properties > java编译器>错误/警告>已弃用的 API

更改要忽略/警告的错误

Maybe your jre system library is 1.8

or eclipse: Project Properties > java compiler > Errors/Warnings > Deprecated API

change Error to ignore/warning

旧街凉风 2025-01-03 03:21:38

看一下这里链接

1. Open project properties.
2. Select Java Build Path node.
3. Select Libraries tab.
4. Remove JRE System Library.
5. Add Library JRE System Library.

作为Milad 建议

尽管这会起作用,但这违背了所有推荐的 Java 运行时策略。最佳实践是避免使用 rt.jar(或任何其他 Sun 提供的运行时库,如 tools.jar)

Take a look here Link

1. Open project properties.
2. Select Java Build Path node.
3. Select Libraries tab.
4. Remove JRE System Library.
5. Add Library JRE System Library.

As Milad suggested

Even though this WILL work, this goes against all recommended Java Runtime policies. The best practice is to avoid using rt.jar (or any other Sun supplied runtime library for that matter, like tools.jar)

烦人精 2025-01-03 03:21:38

这些位于 rt.jar 中,该 jar 文件被 JVM 用作运行时设施,我强烈建议您不要将其添加为项目的依赖项。

了解原因此处

此处描述了执行所需操作的正确方法。

These are in rt.jar, the jar file used as run-time facilities by the JVM, and I would strongly recommend you against adding it as a dependency to your project.

See why here.

The correct way to do what you want to do is described here.

享受孤独 2025-01-03 03:21:38

问题是,您正在从 sun.com.* 包导入库。 Oracle 实际上不鼓励使用这些包,因为它们可能会在未来版本中删除,或者可能不适用于所有 JVM 实现。

如果您尝试导入 sun.com.* 库,您的 IDE(您使用的是哪一个?)可能被配置为生成错误,在这种情况下,配置更改将允许您使用这些库,但这无论如何都不是一个好主意。您应该使用没有访问限制的库来寻找您所寻求的功能的其他替代方案。

另外,如果您只想读取或写入 JPEG 文件,请查看 ImageIO 类,里面有很多有用的方法。

The problem is, that you're importing libraries from the sun.com.* package. Oracle actually discourages the use of these packages, since they could be removed in future releases or may not be available in all JVM implementations.

It's possible that your IDE (which one are you using?) is configured for generating errors if you try to import sun.com.* libraries, in that case a configuration change will allow you to use those libraries, but it wouldn't be a good idea anyway. You should look for other alternatives to the functionality you seek, using libraries with no access restrictions.

Also, if what you want is to simply read or write a JPEG file, take a look at the ImageIO class, there are plenty of useful methods in there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文