Set Java version in maven [UPDATED]

Since developers mostly use version control systems like SVN or GIT with their projects and use either ANT or MAVEN for building these projects there is mostly the question what to do with the Java version used in the project and every developer that can use this project would need to set the Java version in his build path every time he imported this project into his IDE. Since I use maven in my projects I thought “Why not tell maven which Java version I need”. Still you need the version in your installed JREs (Preferences -> Java -> Installed JREs) but if you already did that you can tell maven to use it with the following code:


Now you can see in the marked lines the source and target version are 1.7 which means the Java version you will need/use is Java 7.

Update your Project with Right-Click -> Maven -> Update Project and there you have it, now you can tell maven to manage your Java versions in your projects pom.xml.

UPDATE: If you want to use Java 8 then you need to set the source and target to 1.8 and use the 3.6.1 version of the mave-compiler-plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *