maven不能在java 1.6中编译

时间:2013-02-11 08:41:20

标签: eclipse maven

如何强制maven编译1.6兼容源

我在eclipse中使用maven制作了web-app项目。将web.xml更改为使用3.0版本 - >然后更新配置,现在我无法启动tomcat。 我发现我必须强制maven编译源1.6兼容,我必须添加

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
 <configuration>
    <source>1.7</source>
    <target>1.7</target>
    <showDeprecation>true</showDeprecation>
    <showWarnings>true</showWarnings>
    <executable>${env.JAVA_HOME_7}/bin/javac</executable>
    <fork>true</fork>
</configuration>

但是eclipse中的有效pom是不可编辑的

那么是否有与eclipse兼容的maven或强制maven编译源1.6版本的任何其他方式?

3 个答案:

答案 0 :(得分:5)

你有它。只需输入1.6而不是1.7:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.0</version>
    <configuration>
      <source>1.6</source>
      <target>1.6</target>
    </configuration>
  </plugin>

请参阅:http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

如果不需要,我也会避免额外的配置。

答案 1 :(得分:1)

编辑:

只需使用1.7 java 1.6。

EDIT2:

您的版本:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.7</source>
      <target>1.7</target>
      <showDeprecation>true</showDeprecation>
      <showWarnings>true</showWarnings>
      <executable>${env.JAVA_HOME_7}/bin/javac</executable>
      <fork>true</fork>
    </configuration>
</plugin>

应该是:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.6</source>
      <target>1.6</target>
      <showDeprecation>true</showDeprecation>
      <showWarnings>true</showWarnings>
      <executable>${env.JAVA_HOME_7}/bin/javac</executable>
      <fork>true</fork>
    </configuration>
</plugin>

答案 2 :(得分:0)

只是为了澄清:

在您的项目POM中,您实际上并未编写所有配置,而是覆盖(并最终添加功能)默认配置。

Eclipse中的“有效POM”显示了它的结果,所以确实这是不可编辑的。

但是,如果在POM中添加一些配置(如其他答案中提议的那样),它将覆盖默认设置。它将按原样使用,并将显示在“有效POM”中。

相关问题