Java 7 in Maven Project

If you have both jdk6 and jdk7 installed and you would want to interchange between the two compilers in a maven project, this can be easily done by the maven-compiler-plugin and its source and target parameters.

Assuming that we have created a JAVA_7_HOME environment variable we can point the maven-compiler-plugin to the jdk7 compiler as follows:

  		<plugin>
  			<groupId>org.apache.maven.plugins</groupId>
  			<artifactId>maven-compiler-plugin</artifactId>
  			<version>2.3.2</version>
  			<configuration>
  				<source>1.7</source>
  				<target>1.7</target>
  				<encoding>${project.build.sourceEncoding}</encoding>			
  				<executable>${env.JAVA_7_HOME}</executable>
  			</configuration>
  		</plugin>

I have also created a 2-module Maven project one for each jdk that you can find in this Github repository.