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>