修改maven3项目的默认的编译级别(compile level)

源:http://hi.baidu.com/hi_hi/item/765ec8bbc49880d384dd79d1
评:


听闻maven的鼎鼎大名打算在最近的一个项目中试下爽,结果遇到了这个问题,虽对项目影响不大,但做技术刨根问题是必须的了,少废话。

1.cmd命令建立web项目:mvn archetype:generate -DgroupId=biz.yunduo -DartifactId=dts -DpackageName=dts -DarchetypeArtifactId=maven-archetype-webapp

2.如下图,eclipse3.6 For javaEE下有个警告,意思是项目Build path指定的jre是j2se1.5但是找不到与此版本严格匹配的jre
3.纠结了好长时间,不如看看maven的配置文件吧。打开%maven_home%\conf\setting.xml

在<profiles>标签内添加如下配置:

<profile>
<id>jdk-1.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>

以后再使用maven生成项目默认编译级别就是1.6的了

4.如果你有特别的需要,比如不同的项目使用的jre不同那么可以在项目的pom.xml里添加如下配置:

<build>

    <plugins>

        <plugin>

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

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

            <configuration>

                <source>1.6</source>

                <target>1.6</target>

            </configuration>

        </plugin>

    </plugins>

</build>

猜你喜欢

转载自mauersu.iteye.com/blog/2151788