maven创建java工程时设置编译版本

用maven创建java工程时,默认的编译版本是jdk1.5。可以在setting.xml中改变默认的编辑版本,在Setting.xml文件中的激活profile中添加以下属性:

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

也可以在项目的pom文件中,加入以下配置:

<plugin>

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

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

<version>2.0.2</version>

<configuration>

<source>1.6</source>

<target>1.6</target>

<encoding>${project.build.sourceEncoding}</encoding>

</configuration>

</plugin>

猜你喜欢

转载自sunx.iteye.com/blog/2026245