在maven工程指定java版本并指定编码格式

1.第一种在pom直接指定java版本

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                      <source>1.8</source>
                      <target>1.8</target>
                   </configuration>
              </plugin>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
     <properties>
            <!-- 指定编码,防止update project 如果不加update project 一下还是会变成GBK -->
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

 第二种指定编码

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

 

2.在maven仓库的配置文件中指定settings.xml

 

<!-- 默认指定java版本 -->
    <profile>     
      <id>JDK-1.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> 

 

posted @ 2018-09-09 14:51  Masukotto&xiaou  阅读(557)  评论(0编辑  收藏  举报