This shot discusses different ways to set the Java version in Maven projects.
Maven is a tool used to build and package Java applications.
Maven uses the JAVA_HOME
environment variable to find which Java version it is supposed to run. If a different version of Java is needed, set the JAVA_HOME
to the path of the specific version of JDK.
For example, if Java 8 is needed:
JAVA_HOME=/usr/local/java8
The following properties can be configured to set the Java version in Maven.
maven.compiler.source
maven.compiler.target
In the pom.xml
, add the above two properties.
If Java 8 is needed:
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
Add the source
and target
while you configure the Maven compiler plugin in the pom.xml
file.
If Java 8 is needed, refer to the following code.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>