How do I compile a maven project to a particular version of Java?
Author: Deron Eriksson
Description: This tutorial describes how to compile a maven project to a particular version of Java using the maven compiler plugin.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1) || Tomcat 6.0.14
The maven-compiler-plugin can be used to compile a mavenSW project to a particular version of JavaSW. For example, the plugin entry below specifies to compile the project in question to Java 1.6. The source element is used to "Provide source compatibility with specified release". The target element is used to "Generate class files for specific VM version".
pom.xml maven-compiler-plugin reference
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin>
An example of how this compiler plugin can be useful is if you are running Java 1.5 or 1.6 locally but need to deploy your app to a Java 1.4 production server. You could specify to compile to 1.4.
If you're running a version of Java locally that's higher than the version of Java on the server that you're deploying to, you might see an error message such as the following:
(Continued on page 2)