Maven没有在Eclipse上看到编译器

时间:2015-07-18 18:28:14

标签: java eclipse maven maven-compiler-plugin

My Maven项目没有看到编译器 - 这是Eclipse上的JavaSE-1.8。编译器在Eclipse中的其他任何地方运行良好。

我不断得到的错误是:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project DNM: Compilation failure

[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

我的pom.xml如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>AxyMVN</groupId>
  <artifactId>DNM</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>DNM</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

  <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
  </dependencies>
</project>

项目编译器的配置似乎很好:

    Project Explorer窗口上的
  • ,项目上的JRE System Library显示它已设置为JavaSE-1.8

  • 项目的Java Compiler属性设置为Use compliance from execution environment 'JavaSE-1.8' on the Java Build Path

  • 在项目的Run Configurations窗口中,在Right-click > Run as > Run configurations上打开的窗口, JRE标签显示它已设置为Workspace default JRE (jre1.8.0_20)

将以下内容添加到<properties>中的pom.xml标记并未发生任何变化。

 <maven.compiler.source>1.8</maven.compiler.source>
 <maven.compiler.target>1.8</maven.compiler.target>

每次尝试配置时,我都没有跳过Maven > Update Project

项目在其他任何地方都没有显示任何其他错误。

我错过了什么?

注意:我在其他一些讨论中看到Maven "build path specifies execution environment J2SE-1.5", even though I changed it to 1.7

2 个答案:

答案 0 :(得分:1)

它实际上是在对你说“也许你是在JRE而不是JDK上运行?”,这意味着 - 不要在jre上运行,而是在jdk上运行。下载jdk版本并配置它,祝你好运

答案 1 :(得分:0)

Window → Preferences → Java → Installed JREs.修复了它。它设置为JRE--设置JDK--我的JAVA_HOME显示的那个。

Eclipse/Maven error: "No compiler is provided in this environment"帮助了它。