In pom.xml, defined this maven.compiler.source properties to configure Maven to use Java 8 to compile the project.
Sometimes when you may need to compile a certain project to a different version than what you are currently using. The javac can accept such command using -source and -target. The Compiler Plugin can also be configured to provide these options during compilation.
For example, if you want to use the Java 8 language features (-source 1.8) and also want the compiled classes to be compatible with JVM 1.8 (-target 1.8), you can either add the two following properties, which are the default property names for the plugin parameters:
or configure the plugin directly:
Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version. The pitfall is unintended usage of APIs that only exist in later JREs which would make your code fail at runtime with a linkage error. To avoid this issue, you can either configure the compiler's boot classpath to match the target JRE
Sometimes when you may need to compile a certain project to a different version than what you are currently using. The javac can accept such command using -source and -target. The Compiler Plugin can also be configured to provide these options during compilation.
For example, if you want to use the Java 8 language features (-source 1.8) and also want the compiled classes to be compatible with JVM 1.8 (-target 1.8), you can either add the two following properties, which are the default property names for the plugin parameters:
1.
<
project
>
2.
[...]
3.
<
properties
>
4.
<
maven
.compiler.source
=
""
>1.8</
maven
>
5.
<
maven
.compiler.target
=
""
>1.8</
maven
>
6.
</
properties
>
7.
[...]
8.
</
project
>
or configure the plugin directly:
01.
<
project
>
02.
[...]
03.
<
build
>
04.
[...]
05.
<
plugins
>
06.
<
plugin
>
07.
<
groupid
>org.apache.maven.plugins</
groupid
>
08.
<
artifactid
>maven-compiler-plugin</
artifactid
>
09.
<
version
>3.6.1</
version
>
10.
<
configuration
>
11.
<
source
>1.8
12.
<
target
>1.8</
target
>
13.
</
configuration
>
14.
</
plugin
>
15.
</
plugins
>
16.
[...]
17.
</
build
>
18.
[...]
19.
</
project
>
Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version. The pitfall is unintended usage of APIs that only exist in later JREs which would make your code fail at runtime with a linkage error. To avoid this issue, you can either configure the compiler's boot classpath to match the target JRE
0 comments:
Post a Comment