背景

使用 maven 3.x 安装到本地后,创建的项目一般都是基于JDK1.5版本。而目前大多数的项目已经升级到1.6或以上,尤其是Servlet3.0 已经要求Java6或以上版本的环境,往往需要改动。

解决方案

方案一:全局设置

在${MAVEN_HOME}/conf/setting.xml中改变默认的编译版本,激活profile:

<profile>   
    <id>jdk1.6</id>
    <activation>   
    <activeByDefault>true</activeByDefault>
    <jdk>1.6</jdk>   
    </activation>
    <properties>   
           <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
        <maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion>   
    </properties>   
</profile>  

 

方案二:项目单独配置

修改pom文件中,加入以下配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <encoding>${project.build.sourceEncoding}</encoding>
    </configuration>
</plugin>

 

相关文章:

  • 2021-09-25
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2021-05-07
  • 2021-05-31
  • 2022-12-23
猜你喜欢
  • 2022-01-13
  • 2021-07-28
  • 2022-01-16
  • 2022-12-23
  • 2021-11-30
  • 2021-08-10
  • 2021-06-09
相关资源
相似解决方案