Java Advanced Imaging with Maven

After serveral tries to combine Java Advanced Imaging (JAI) with a Maven project I finally succeeded. The main problem as it is often in such cases is that there is not enough documentation on the subject in the web. I am sure that countless programmer had the same problem, but after they solved the problem they did not document it or if they did their solution is unsatisfactory for an open source project (e.g. installing the JAI dependencies in your local repository). Therefore here is my solution:

The problem is the licence terms of JAI that do not allow the JAR files to be put into a repository. What is done instead is, that there is a pom file that points to an URL from where the JAR file can be downloaded. Therefore the trick is to not specify the dependencies as jar but as pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>ch.sahits.image</groupId>
	<artifactId>JAI</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>JAI</name>
	<description>JAI depencies</description>
	<repositories>
		<repository>
			<id>JBoss</id>
			<name>Maven JBoss Nexus</name>
			<layout>default</layout>
			<url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
		<repository>
			<id>maven2</id>
			<name>Maven central</name>
			<layout>default</layout>
			<url>http://repo1.maven.org/maven2/</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>
	<dependencies>
		<dependency>
			<groupId>javax.media</groupId>
			<artifactId>jai_core</artifactId>
			<version>1.1.3</version>
			<type>pom</type>
		</dependency>
		<dependency>
			<groupId>com.sun.media</groupId>
			<artifactId>jai_codec</artifactId>
			<version>1.1.2_01</version>
			<type>pom</type>
			<exclusions>
				<exclusion>
					<groupId>javax.media</groupId>
					<artifactId>jai_core</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>com.sun.media</groupId>
			<artifactId>jai_imageio</artifactId>
			<version>1.1</version>
			<type>pom</type>
			<exclusions>
				<exclusion>
					<groupId>javax.media</groupId>
					<artifactId>jai_core</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<!-- <dependency> <groupId>com.sun</groupId> <artifactId>mlibwrapper_jai</artifactId> 
			<version>1.1.3</version> </dependency> -->
	</dependencies>
	<organization>
		<name>Sahits GmbH</name>
		<url>http://www.sahits.ch</url>
	</organization>
	<licenses>
		<license>
			<name>Apache 2</name>
			<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
			<distribution>repo</distribution>
			<comments>A business-friendly OSS license</comments>
		</license>
	</licenses>
	<developers>
		<developer>
			<id>hotzst</id>
			<name>Andi Hotz</name>
			<email>andi.hotz@sahtis.ch</email>
			<url>http://www.sahits.ch</url>
			<organization>Sahits GmbH</organization>
			<organizationUrl>http://www.sahits.ch</organizationUrl>
			<roles>
				<role>developer</role>
			</roles>
			<timezone>+1</timezone>
		</developer>
	</developers>
</project>

This pom file specifies com.sun.media:jai_codec;1.1.2_01, com.sun.media:jai_imageio:1.1 and javax.media:jai_core:1.1.3. The first two have a dependency on the last one with version 1.1.2_01. Therefore the indirect dependency on those two is explicitly excluded in favour of the current release 1.1.3.

Schreibe einen Kommentar