聽聞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>