修改默认的java版本 maven项目

来源:互联网 发布:linux c fork 编辑:程序博客网 时间:2024/04/29 13:59

如题:maven构建的项目中默认的java版本是1.5,并且我们在项目属性里面更改了之后,

在maven-update project后又会变成默认的1.5版本,甚为烦恼。

下面提供解决方法:


1:在maven的setting.xml文件中设置

<profile>   

    <id>jdk1.8</id>

    <activation>   

    <activeByDefault>true</activeByDefault>

    <jdk>1.8</jdk>   

    </activation>

    <properties>   

     <maven.compiler.source>1.8</maven.compiler.source>

     <maven.compiler.target>1.8</maven.compiler.target>

     <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>   

    </properties>   

</profile> 


2:在项目的pom.xml文件中设置


<plugin>  

        <groupId>org.apache.maven.plugins</groupId>  

        <artifactId>maven-compiler-plugin</artifactId>  

        <version>3.3</version>  

        <configuration>   

          <source>1.7</source>  

          <target>1.7</target>  

        </configuration>  

</plugin> 



推荐第一种,因为在maven的setting文件中设置只需要设置一次,而在项目中设置,就需要没创建一个项目都要设置一次。

0 0
原创粉丝点击