Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Java Advanced Imaging with Maven

Tags:

java

maven-2

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.

like image 374
Robert Munteanu Avatar asked Jul 30 '09 21:07

Robert Munteanu


3 Answers

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

like image 186
Lol Avatar answered Oct 16 '22 08:10

Lol


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>
like image 14
manuna Avatar answered Oct 16 '22 07:10

manuna


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.

like image 12
Mike Cornell Avatar answered Oct 16 '22 08:10

Mike Cornell