【问题标题】:maven does not compile in java 1.6maven 无法在 java 1.6 中编译
【发布时间】:2013-01-26 08:11:46
【问题描述】:

如何强制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版本的方法?

【问题讨论】:

    标签: eclipse maven


    【解决方案1】:

    只是为了澄清:

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

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

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

    【讨论】:

      【解决方案2】:

      编辑:

      只需使用 java 1.6 而不是 1.7。

      编辑2:

      你的版本:

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

      【讨论】:

        【解决方案3】:

        你有它。只需输入 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

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

        【讨论】:

          猜你喜欢
          • 2015-03-14
          • 2012-05-28
          • 1970-01-01
          • 2021-07-23
          • 2011-10-24
          • 1970-01-01
          • 2011-02-06
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多