Maven maven-compiler-plugin 编译问题

问题:每次右键项目名-maven->update project 时候,项目jdk版本变了,变回1.5版本或者其他版本

 

解决方案一:修改maven的配置(解压目录的conf\setting.xml文件)

<profile>
    <id>jdk1.6</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.6</jdk>
    </activation>
    <properties>
        <!-- want to use the Java 8 language features, Default 1.5 -->
        <maven.compiler.source>1.6</maven.compiler.source>
        <!-- want the compiled classes to be compatible with JVM 1.8, Default 1.5 -->
        <maven.compiler.target>1.6</maven.compiler.target>
        <!-- Version of the compiler to use, ex. "1.3", "1.5", if fork is set to true -->
        <maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion>
    </properties>
</profile> 

解决方案二:默认settigs.xml文件路径为:c:\users\xxx\.m2\settings.xml,只要把设置好的settings.xml文件复制到该目录下

解决方案三:修改项目中的pom.xml

<plugins>
    <!--
        指定maven插件编译版本
        1:maven:since2.0, 默认用jdk1.3来编译,maven 3.x 貌似是默认用jdk 1.52:windows默认使用GBK编码,java项目经常编码为utf8,也需要在compiler插件中指出,否则中文乱码可能会出现编译错误。 
     -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <!-- since 2.0 -->
        <version>3.7.0</version>
        <configuration>
            <!-- use the Java 8 language features -->
            <source>1.8</source>
            <!-- want the compiled classes to be compatible with JVM 1.8 -->
            <target>1.8</target>
            <!-- The -encoding argument for the Java compiler. -->
            <encoding>UTF8</encoding>
        </configuration>
    </plugin>
</plugins>

 

posted @ 2017-11-16 23:48  ^梦幻星空^  阅读(33908)  评论(1编辑  收藏  举报