In this tutorial we will show you how to deal with issues concerning the JDK version of a Maven based Java project. Apache Maven uses by default the JDK-1.5 version. A common problem is to use features supported by later versions.
In this example, we use the following tools on a Windows 7 platform:
- Apache Maven 3.1.1
- Maven Source Plugin
- JDK 1.7
Usually, the JDK version is not specified inside the
pom.xml file and thus, Maven uses the default, 1.5 version. However, this version is rather old and does not support new features. For example:
As we can observe from the reported error, a switch statement cannot support a Java String in JDK-1.5. Thus, since our project requires the usage of a switch statement over a String, we must use the latest JDK version. In order to achieve that, we make use of Maven’s Compiler Plugin.
In order to explicitly define our project to be compiled, using the JDK-1.7 version, we add the following snippet to our
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin>
Now, if we rebuild our project, the error will not show up.
This was a tutorial on how to resolve issues regarding the JDK version of a project, using Maven’s Compiler Plugin.