Skip to content

Building with Old Java Versions

Peter Skocovsky edited this page Aug 12, 2016 · 2 revisions

Temporarily use Maven Toolchain Plugin. This includes adding the toolchains.xml file to the local ${user.home}/.m2 directory. This file points to JVM-s that are available on the particular computer where the project is built, so it does not make much sense including this plugin in the POM permanently.

Example plugin declaration in POM:

...
		<plugins>
			...
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-toolchains-plugin</artifactId>
				<version>1.1</version>
				<executions>
					<execution>
						<goals>
							<goal>toolchain</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<toolchains>
						<jdk>
							<version>1.6</version>
							<vendor>sun</vendor>
						</jdk>
					</toolchains>
				</configuration>
			</plugin>
			...
		</plugins>
...

Example toolchains.xml file:

<?xml version="1.0" encoding="UTF8"?>
<toolchains>
  <!-- JDK toolchains -->
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>1.6</version>
      <vendor>sun</vendor>
    </provides>
    <configuration>
      <jdkHome>/path/to/your/1.6.0.jdk/home</jdkHome>
    </configuration>
  </toolchain>
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>1.7</version>
      <vendor>oracle</vendor>
    </provides>
    <configuration>
      <jdkHome>/path/to/your/jdk1.7.0_79.jdk/home</jdkHome>
    </configuration>
  </toolchain>
</toolchains>