【问题标题】:Maven gives a java version error (ask for java 1.5) even when I have java 1.7 installed即使我安装了 java 1.7,Maven 也会出现 java 版本错误(要求 java 1.5)
【发布时间】:2013-04-30 09:20:17
【问题描述】:

我收到一个错误提示

(使用 -source 5 或更高版本来启用注释){class path} 错误: -source 1.3 不支持 for-each 循环

当我尝试使用 maven 编译模块时。

问题是我机器中的java版本是1.7.0_02

谁能提出解决方案?

【问题讨论】:

  • 你安装了java 7很好,但它与错误无关。请发布您的pom.xml
  • 您使用的是 Maven 2 还是 3?

标签: java maven


【解决方案1】:

您可能希望将其包含在您的 pom.xml 文件中,因为我遇到了同样的问题:

<build>
  <pluginManagement>
      <plugins>
          <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>2.3.2</version>
              <configuration>
                  <source>1.6</source>
                  <target>1.6</target>
                  <compilerArgument></compilerArgument>
              </configuration>
          </plugin>
      </plugins>
  </pluginManagement>

【讨论】:

  • 实际上,他应该将这段代码中所有出现的 1.6 替换为 1.7,但仍然:+1
  • 我把它放在了父pom中,但仍然无法编译
  • 你把它放在你的 pom.xml 文件的什么地方,我们能看到 pom.xml 文件吗?此外,您可能希望将源更改为 1.7,目标更改为 1.7 而不是 1.6。
  • 是的。我首先做了这些改变。我把它放在父 pom 中并从相关模块中引用它。
【解决方案2】:

请检查 JAVA_HOME 环境变量的值。
对于maven使用的用户acc

【讨论】:

    【解决方案3】:

    最短的版本是在你的 pom.xml 中设置 maven.compiler.sourcemaven.compiler.target 属性:

    <project>
       ....
       <properties>
           <maven.compiler.source>1.5</maven.compiler.source>
           <maven.compiler.target>1.5</maven.compiler.target>
       </properties>
    

    【讨论】:

      【解决方案4】:
      <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <source>1.5</source>
                        <target>1.5</target>
                        <compilerArgument></compilerArgument>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
      

      黑豹

      这个也是

      <project>
         ....
         <properties>
             <maven.compiler.source>1.5</maven.compiler.source>
             <maven.compiler.target>1.5</maven.compiler.target>
         </properties>
      

      通过 rzymek

      大家一起

      清理并构建项目,这很好用!!!

      【讨论】:

        【解决方案5】:
        <build>
        <finalName>your project name</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
        

        【讨论】:

          猜你喜欢
          • 2022-11-29
          • 2013-08-27
          • 2021-05-22
          • 2021-10-25
          • 2015-04-27
          • 2019-12-13
          • 1970-01-01
          • 2017-01-23
          • 1970-01-01
          相关资源
          最近更新 更多