IntelliJ IDEA14.1中java项目Maven中没有配置JDK时的问题

在IntelliJ IDEA 14.1中使用在java项目中使用Maven时当没有在Maven中配置JDK编译版本、源码版本时,IDEA将默认的编译版本、源码版本设置为jdk5。

在IDEA中Language level 将使用默认的JDK5级别

目标版本也是默认为JDK5

 

当手动改为其他版本如:JDK8,但当你重新载入Maven项目时IDEA又将默认的Language level、Target bycode version设置为JDK5。

在项目中你将看到如下问题:

源值1.5已过时,将在未来所有版本中删除

目标值1.5已过时,将在未来所有版本中删除

这是因为IDEA默认把项目的源代码版本设置为jdk1.5,目标代码设置为jdk1.5

 

 

解决方案: 

在项目的pom.xml文件中添加:

1 <properties>
2         <maven.compiler.source>1.8</maven.compiler.source>
3         <maven.compiler.target>1.8</maven.compiler.target>
4 </properties>

或者修改Maven的Settings.xml文件添加如下内容:

 1 <profile>
 2            <id>jdk-1.8</id>
 3            <activation>
 4               <activeByDefault>true</activeByDefault>
 5               <jdk>1.8</jdk>
 6             </activation>
 7                     <properties>
 8                        <maven.compiler.source>1.8</maven.compiler.source>
 9                             <maven.compiler.target>1.8</maven.compiler.target>
10                              <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> 
11                     </properties>
12 </profile>

修改后IDEA将在源码jdk版本、目标jdk版本使用Maven中配置的jdk版本。

IntelliJ IDEA 的详细介绍请点这里
IntelliJ IDEA 的下载地址请点这里

猜你喜欢

转载自www.linuxidc.com/Linux/2016-03/129507.htm