在 Maven 中使用 Java 高级成像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1209583/
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
Using Java Advanced Imaging with Maven
提问by Robert Munteanu
The JAI setupis 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.
该JAI设置是相当繁琐,涉及多个罐子和环境变量。如果我可以将它添加为常规的 Maven 依赖项,它将大大有助于项目的可移植性。
The POM snippet I'm using is
我正在使用的 POM 片段是
<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:
当然,我可以下载并安装这些 jar。问题是双重的:
- jai_imageio requires two jars;
- jai_imageio requires a native library to be installed and two environment variables to be set.
- jai_imageio 需要两个罐子;
- jai_imageio 需要安装一个本地库并设置两个环境变量。
I have not found a way to make this work with Maven.
我还没有找到一种方法来使这个工作与 Maven 一起工作。
See Reading JCS_YCCK images using ImageIOfor the reason I'm using JAI.
关于我使用 JAI 的原因,请参阅使用 ImageIO 读取 JCS_YCCK 图像。
采纳答案by Robert Munteanu
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.
我没有看到的是 JAI 依赖只需要在运行时得到满足,因此我通过为 Tomcat 配置它来确保生产环境可以访问 JAI。
回答by Mike Cornell
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-pluginto validate that the environment settings are there.
您将需要下载 jar 并将它们安装在您的本地 Maven 存储库或本地存储库代理服务器(Nexus/Artifactory)中。我认为您可以使用maven-enforcer-plugin来验证环境设置是否存在。
The licencefor jai_imageio doesn't allow for it to be distributed.
回答by I-yorn-man
try this:
尝试这个:
<dependency>
<groupId>com.sun.media</groupId>
<artifactId>jai_imageio</artifactId>
<version>1.1</version>
<type>pom</type>
</dependency>
回答by Lol
To avoid donwloading the jars and installing them you can add a dependency on the spring repo. So change the normal dependency slightly:
为了避免下载 jars 并安装它们,您可以添加对 spring 仓库的依赖。所以稍微改变一下正常的依赖:
<dependency>
<groupId>javax.media.jai</groupId>
<artifactId>com.springsource.javax.media.jai.core</artifactId>
<version>1.1.3</version>
</dependency>
and add a repository declaration:
并添加存储库声明:
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
And it should now work (it makes all the sun classes available javax.media.jai.*). See here:
现在它应该可以工作了(它使所有的 sun 类都可用 javax.media.jai.*)。看这里:
You can also add the codec dependency if necessary...
如有必要,您还可以添加编解码器依赖项...
回答by manuna
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.
有一个 JAI-imageio 的“独立”实现,不依赖于 jai_core。它不需要 JAI 安装到您的 JDK 和 JRE,只需要单个 Maven 依赖项。
In Maven, add it's repository:
在 Maven 中,添加它的存储库:
<repository>
<releases />
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>mygrid-repository</id>
<name>myGrid Repository</name>
<url>http://www.mygrid.org.uk/maven/repository</url>
</repository>
and dependency:
和依赖:
<dependency>
<groupId>net.java.dev.jai-imageio</groupId>
<artifactId>jai-imageio-core-standalone</artifactId>
<version>1.2-pre-dr-b04-2014-09-13</version>
</dependency>
See its sitefor more details
查看其网站了解更多详情
PS Updated after a useful comment (another dependency from gitHub which does not need adding that repository):
PS 在有用的评论后更新(来自 gitHub 的另一个依赖项,不需要添加该存储库):
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-core</artifactId>
<version>1.3.0</version>
</dependency>
回答by GregNash
This worked for me:
这对我有用:
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-coverage</artifactId>
<version>2.7.4</version>
</dependency>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
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.
似乎 gt-coverage 依赖于 jai_imageio,所以它为我安装了合适的 jars。我什至不需要更改我的代码来使用这个工件。
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 hereand here. Note the extra lines in the 2nd link because they are necessary. Here's the extra code to go in your pom:
这将使您的代码在您的 IDE 中工作。但是,如果您想要一个可执行的 jar,那么您需要使用 Maven Shade 插件。此处和此处描述了它的使用。请注意第二个链接中的额外行,因为它们是必需的。这是要添加到您的 pom 中的额外代码:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.companyname.packagename.MainClassName</Main-Class>
<Specification-Title>Java Advanced Imaging Image I/O Tools</Specification-Title>
<Specification-Version>1.1</Specification-Version>
<Specification-Vendor>Sun Microsystems, Inc.</Specification-Vendor>
<Implementation-Title>com.sun.media.imageio</Implementation-Title>
<Implementation-Version>1.1</Implementation-Version>
<Implementation-Vendor>Sun Microsystems, Inc.</Implementation-Vendor>
<Extension-Name>com.sun.media.imageio</Extension-Name>
</manifestEntries>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
I don't know what all those extra manifest entries are, but they make my executable jar do what it does in the IDE.
我不知道所有这些额外的清单条目是什么,但它们使我的可执行 jar 执行它在 IDE 中所做的工作。
回答by Chris2M
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:
manunu 的答案中的存储库 url 似乎已更改或至少暂时不可用,这会导致 maven 构建失败。作为替代,可以使用以下网址:
http://build.mygrid.org.uk/maven/repository
http://build.mygrid.org.uk/maven/repository
<repository>
<releases />
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>mygrid-repository</id>
<name>myGrid Repository</name>
<url>http://build.mygrid.org.uk/maven/repository</url>
</repository>
回答by Swarit Agarwal
<dependency>
<groupId>javax.media.jai</groupId>
<artifactId>com.springsource.javax.media.jai.core</artifactId>
<version>1.1.3</version>
</dependency>
and add a repository declaration:
并添加存储库声明:
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
This worked for me. I guess it relies on Spring Jar.
这对我有用。我猜它依赖于 Spring Jar。
回答by edilon Junior
I add this dependencies in my pom file:
我在我的 pom 文件中添加了这个依赖项:
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-core</artifactId>
<version>1.4.0</version>
</dependency>
from https://openmeetings.apache.org/openmeetings-web/dependencies.html
来自https://openmeetings.apache.org/openmeetings-web/dependencies.html