打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
【Maven冷知识】Compiler插件

很多同学在pom的配置中都喜欢加上这样一段配置信息:

从配置信息上看,这是maven对Java源代码进行的编译配置,采用了Java 7 进行编译,但是为什么要加上这段配置呢?不加有没有什么影响?很多同学并不能准确回答这些问题,其本质在于一知半解没有深入的理解这些配置信息的作用。

以下信息 来自于Apache Maven的官方信息:

The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.

Also note that at present the default source setting is 1.6 and the default target setting is 1.6, independently of the JDK you run Maven with. You are highly encouraged to change these defaults by setting source and target as described in Setting the -source and -target of the Java Compiler.

Other compilers than javac can be used and work has already started on AspectJ, .NET, and C#.

主要讲述的有以下三点:

(1)Compiler Plugin插件是用来编译项目源代码的,自从Maven 3.0版本之后,默认的编译Java源代码的编译器是javax.tools.JavaCompiler(JDK默认的Java编译器是javac),如果你想使用默认的javac编译器,可以在插件中进行配置:

这个配置一般情况下没有必要修改,除非项目有特殊要求。

(2)目前使用的默认的source和target都是1.6版本,而最新的JDK版本为11,因此强烈建议开发者在实际开发中修改,可以通过下面两种可选方式进行配置修改:

第一种方式是:

第二种方式是:

这两种方式是二选一的,并不是全部都要加上,而很多同学在开发中,都会全部加上。

(3)除了使用javac编译器以外,还可以使用AspectJ、.Net、C#等,这意味者今后maven不仅仅可以编译java工程项目,还可以编译微软的C#之类的项目,功能将会变得更加强大,应用范围更广。

4. 结语


参考文献 

[1] Welcome to Apache Maven.[EB/OL]. http://maven.apache.org/

[2]Java SE Downloads [EB/OL].https://www.oracle.com/technetwork/java/javase/downloads/index.html

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
maven学习笔记
maven教程3_maven-compiler-plugin
Joint Compilation of Scala and Java Sources
深入理解java类版本冲突的问题
build.plugins.plugin.version 报错导致
程序包com.sun.image.codec.jpeg不存在 问题的完美解决
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服