Setting the -source and -target of the Java Compiler
来源:互联网 发布:mac ext4 读写 编辑:程序博客网 时间:2024/05/20 22:29
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:
- <project>
- [...]
- <properties>
- <maven.compiler.source>1.8</maven.compiler.source>
- <maven.compiler.target>1.8</maven.compiler.target>
- </properties>
- [...]
- </project>
or configure the plugin directly:
- <project>
- [...]
- <build>
- [...]
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.6.1</version>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
- </plugins>
- [...]
- </build>
- [...]
- </project>
Note: 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 or use the Animal Sniffer Maven Plugin to verify your code doesn't use unintended APIs. In the same way, setting the sourceoption does not guarantee that your code actually compiles on a JDK with the specified version. To compile your code with a specific JDK version, different than the one used to launch Maven, refer to the Compile Using A Different JDKexample.
- Setting the -source and -target of the Java Compiler
- iOS-Verify the value of the CODE_SIGN_ENTITLEMENTS build setting for target "xxx" and build conf
- The betray of compiler
- The Source and Develop of RootKit
- the target of 2010
- Facebook, Google, and the Rise of Open Source Security Software
- The Target of Cocoa application
- java异常:The processing instruction must begin with the name of the target.
- Java compiler level does not match the version of the installed Java project
- Eclipse Java compiler level does not match the version of the installed Java project facet.
- Java compiler level does not match the version of the installed Java project fac
- Java compiler level does not match the version of the installed Java project facet
- Java compiler level does not match the version of the installed Java project fac
- Error: Java compiler level does not match the version of the installed Java project facet.
- "Java compiler level does not match the version of the installed Java project facet"异常解决
- Java compiler level does not match the version of the installed Java project facet.
- Java compiler level does not match the version of the installed Java project fac
- Java compiler level does not match the version of the installed Java project facet
- 十六进制转十进制
- android usb挂载分析--ext*支持uid、gid等选项
- 使用Java远程连接操作Redis
- ios之热更新技术
- PAT 1101
- Setting the -source and -target of the Java Compiler
- 贝叶斯【王者争霸】
- 五,利用node进行DNS解析
- app:transformClassesWithDexForDebug Execution问题解决
- elasticsearch写入数据存储的过程
- 关于编译器与解释器的区别
- iOS JSON返回的数据有NSNull导致程序崩溃及ios nil、NULL和NSNull的区别
- Maven搭建SpringMvc+Spring+Hibernate框架
- 根据font-size计算rem尺寸,动态缩放页面