将 Java 高级成像与 Maven 结合使用

发布于 2024-07-29 22:43:02 字数 1332 浏览 13 评论 0原文

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 技术交流群。

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

发布评论

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

评论(9

少女情怀诗 2024-08-05 22:43:03

您需要下载 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.

荒人说梦 2024-08-05 22:43:03

这对我有用:

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

似乎 gt-coverage 依赖于 jai_imageio,因此它为我安装了适当的 jar。 我什至不需要更改代码就可以使用这个工件。

这将使您的代码在 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>

我不知道所有这些额外的清单条目是什么,但它们使我的可执行 jar 执行它在 IDE 中执行的操作。

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.

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:

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

愿得七秒忆 2024-08-05 22:43:03
<dependency>
    <groupId>javax.media.jai</groupId>
    <artifactId>com.springsource.javax.media.jai.core</artifactId>
    <version>1.1.3</version>
</dependency>

并添加存储库声明:

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

这对我有用。 我猜它依赖于Spring Jar。

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

檐上三寸雪 2024-08-05 22:43:03

manunu 的答案中的存储库 url 似乎已更改或至少暂时不可用,这会导致 Maven 构建失败。 作为替代方案,可以使用以下 url:

http://build.mygrid.org.uk/ Maven/存储库

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

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

<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>
暮年 2024-08-05 22:43:03

我没有看到 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.

鸢与 2024-08-05 22:43:03

尝试这个:

<dependency>
  <groupId>com.sun.media</groupId>
  <artifactId>jai_imageio</artifactId>
  <version>1.1</version>
  <type>pom</type>
</dependency>

try this:

<dependency>
  <groupId>com.sun.media</groupId>
  <artifactId>jai_imageio</artifactId>
  <version>1.1</version>
  <type>pom</type>
</dependency>
娇纵 2024-08-05 22:43:03

我在我的 pom 文件中添加了这个依赖项:

<dependency>
        <groupId>com.github.jai-imageio</groupId>
        <artifactId>jai-imageio-core</artifactId>
        <version>1.4.0</version>
</dependency>   

来自 https://openmeetings.apache.org/ openmeetings-web/dependency.html

I add this dependencies in my pom file:

<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

小霸王臭丫头 2024-08-05 22:43:02

为了避免下载 jar 并安装它们,您可以添加对 spring 存储库的依赖项。 因此,稍微改变一下正常的依赖关系:

    <dependency>
        <groupId>javax.media.jai</groupId>
        <artifactId>com.springsource.javax.media.jai.core</artifactId>
        <version>1.1.3</version>
    </dependency>

并添加一个存储库声明:

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

它现在应该可以工作(它使所有 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:

    <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:

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

半边脸i 2024-08-05 22:43:02

JAI-imageio 有一个“独立”实现,不依赖于 jai_core。 它不需要将 JAI 安装到 JDK 和 JRE,只需要单个 Maven 依赖项。

在 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>

和依赖项:

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

有关更多详细信息,请参阅 其站点

PS 已更新在有用的评论之后(来自 gitHub 的另一个依赖项,不需要添加该存储库):

<dependency>
    <groupId>com.github.jai-imageio</groupId>
    <artifactId>jai-imageio-core</artifactId>
    <version>1.3.0</version>
</dependency>

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:

<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 site for more details

PS Updated after a useful comment (another dependency from gitHub which does not need adding that repository):

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