Suppose you write a project that must have mandatory support for java 1.6 and higher, but you only have java 9 installed and also want the compiled classes to be compatible with JVM 1.8.
The
javac compiler can accept certain commands
-source and
-target to specify the version of java used in your project
and the version of java for the target assembly.
You can add the following two properties to your pom.xml:
1 2 3 4 |
<properties> <maven.compiler.source>1.6</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> |
or you can configure maven compiler plugin directly with same options:
1 2 3 4 5 6 7 8 9 10 11 |
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> |