Jdk 1.8支持Lambda新特性,想試試直接在IDEA使用,因而建立一個web項目,着手準備使用時,發現瞭如下的問題。環境已經中已經配置了jdk1.8環境java
idea
的project structure配置若是缺乏第三部,會出現以下錯誤web
設置完成以後,若是從新啓動IDEA時,就會發現全部的設置又從新恢復到默認狀態(JDK 1.5)apache
緣由是:maven
Apache Maven Compiler Plugin 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.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.
解釋是:ide
該插件從3.0版本開始, 默認編譯器是javax.tools.JavaCompiler (前提是JDK 1.6之後); 若是想使用javac,須要手動設置。 當前(Version: 3.5.1), 默認使用JDK 1.5解析和編譯源碼, 與運行Maven的JDK版本無關!
PS:ui
<project> [...] <build> [...] <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> [...] </build> [...] </project>
pom.xml中指定compiler的版本idea
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>
固然還有一個簡單寫法spa
<properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>
Jdk 1.8支持Lambda新特性,想試試直接在IDEA使用,因而建立一個web項目,着手準備使用時,發現瞭如下的問題。環境已經中已經配置了jdk1.8環境插件
idea
的project structure配置若是缺乏第三部,會出現以下錯誤code
設置完成以後,若是從新啓動IDEA時,就會發現全部的設置又從新恢復到默認狀態(JDK 1.5)
緣由是:
Apache Maven Compiler Plugin 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.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.
解釋是:
該插件從3.0版本開始, 默認編譯器是javax.tools.JavaCompiler (前提是JDK 1.6之後); 若是想使用javac,須要手動設置。 當前(Version: 3.5.1), 默認使用JDK 1.5解析和編譯源碼, 與運行Maven的JDK版本無關!
PS:
<project> [...] <build> [...] <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> [...] </build> [...] </project>
pom.xml中指定compiler的版本
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>
固然還有一個簡單寫法
<properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>