将 Java 高级成像与 Maven 结合使用
JAI 设置是相当繁琐,涉及多个 jar 和环境变量。 如果我可以将其添加为常规 Maven 依赖项,这将大大有助于项目的可移植性。
我正在使用的 POM 片段是
<dependency>
<groupId>com.sun.media</groupId>
<artifactId>jai_imageio</artifactId>
<version>1.1</version>
</dependency>
,错误是
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) com.sun.media:jai_imageio:jar:1.1
2) javax.media:jai_core:jar:1.1.3
我当然可以下载并安装这些 jar。 问题是双重的:
- jai_imageio 需要两个 jar;
- jai_imageio 需要安装本机库并设置两个环境变量。
我还没有找到一种方法可以让这个与 Maven 一起工作。
请参阅使用 ImageIO 读取 JCS_YCCK 图像了解我使用 JAI 的原因。
The JAI setup is quite tedious, involving multiple jars and environment variables. It would aid the project's portability quite a lot if I could add it as a regular Maven dependency.
The POM snippet I'm using is
<dependency>
<groupId>com.sun.media</groupId>
<artifactId>jai_imageio</artifactId>
<version>1.1</version>
</dependency>
and the errors are
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) com.sun.media:jai_imageio:jar:1.1
2) javax.media:jai_core:jar:1.1.3
I can, of course, download and install those jars. The problem is twofold:
- jai_imageio requires two jars;
- jai_imageio requires a native library to be installed and two environment variables to be set.
I have not found a way to make this work with Maven.
See Reading JCS_YCCK images using ImageIO for the reason I'm using JAI.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您需要下载 jar 并将其安装在本地 Maven 存储库或本地存储库代理服务器 (Nexus/Artifactory) 中。 我认为您可以使用 maven-enforcer-plugin 来验证环境设置在那里。
jai_imageio 的许可证不允许它分布式。
You're going to need to download the jars and install them in your local maven repository, or local repository proxy server (Nexus/Artifactory). I think you can use the maven-enforcer-plugin to validate that the environment settings are there.
The licence for jai_imageio doesn't allow for it to be distributed.
这对我有用:
似乎 gt-coverage 依赖于 jai_imageio,因此它为我安装了适当的 jar。 我什至不需要更改代码就可以使用这个工件。
这将使您的代码在 IDE 中运行。 然而,如果你想要一个可执行的jar,那么你需要使用Maven Shade插件。 它的使用描述为 这里和此处。 请注意第二个链接中的额外行,因为它们是必要的。 以下是要放入 pom 中的额外代码:
我不知道所有这些额外的清单条目是什么,但它们使我的可执行 jar 执行它在 IDE 中执行的操作。
This worked for me:
It seems that gt-coverage depends on jai_imageio, so it installed the appropriate jars for me. I didn't even have to change my code to use this artifact.
This will get your code working within your IDE. However, if you want an executable jar, then you need to use the Maven Shade plugin. Its use is described here and here. Note the extra lines in the 2nd link because they are necessary. Here's the extra code to go in your pom:
I don't know what all those extra manifest entries are, but they make my executable jar do what it does in the IDE.
并添加存储库声明:
这对我有用。 我猜它依赖于Spring Jar。
and add a repository declaration:
This worked for me. I guess it relies on Spring Jar.
manunu 的答案中的存储库 url 似乎已更改或至少暂时不可用,这会导致 Maven 构建失败。 作为替代方案,可以使用以下 url:
http://build.mygrid.org.uk/ Maven/存储库
The repository url in manunu's answer seems to have changed or at least is temporarily unavailable, which causes the maven build to fail. As an alternative, the following url can be used:
http://build.mygrid.org.uk/maven/repository
我没有看到 JAI 依赖项只需要在运行时得到满足,因此我通过为 Tomcat 配置 JAI 来确保生产环境可以访问 JAI。
What I failed to see was that the JAI dependency needed to be satisfied only at runtime, and therefore I made sure the production environment has access to JAI, by configuring it for Tomcat.
尝试这个:
try this:
我在我的 pom 文件中添加了这个依赖项:
来自 https://openmeetings.apache.org/ openmeetings-web/dependency.html
I add this dependencies in my pom file:
from https://openmeetings.apache.org/openmeetings-web/dependencies.html
为了避免下载 jar 并安装它们,您可以添加对 spring 存储库的依赖项。 因此,稍微改变一下正常的依赖关系:
并添加一个存储库声明:
它现在应该可以工作(它使所有 sun 类都可用 javax.media.jai.*)。 请参阅此处:
http ://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.javax.media.jai.core&version=1.1.3
您还可以添加编解码器依赖项,如果必要...
http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.javax.media.jai.codec&version=1.1.3
To avoid donwloading the jars and installing them you can add a dependency on the spring repo. So change the normal dependency slightly:
and add a repository declaration:
And it should now work (it makes all the sun classes available javax.media.jai.*). See here:
http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.javax.media.jai.core&version=1.1.3
You can also add the codec dependency if necessary...
http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.javax.media.jai.codec&version=1.1.3
JAI-imageio 有一个“独立”实现,不依赖于 jai_core。 它不需要将 JAI 安装到 JDK 和 JRE,只需要单个 Maven 依赖项。
在 Maven 中,添加它的存储库:
和依赖项:
有关更多详细信息,请参阅 其站点
PS 已更新在有用的评论之后(来自 gitHub 的另一个依赖项,不需要添加该存储库):
There is a "standalone" implementation of JAI-imageio, without dependencies to jai_core. It doesn't need JAI installation to your JDK and JRE, only single Maven dependency.
In Maven, add it's repository:
and dependency:
See its site for more details
PS Updated after a useful comment (another dependency from gitHub which does not need adding that repository):