java 无法在项目上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46377661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 09:11:34  来源:igfitidea点击:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project

javamaven

提问by Farzan Ali Shaikh

I had a java project which I reconfigured to a Maven project. After reconfiguring and adding most of the dependencies required, I get the following error in console when I run mvn installcommand. I tried the solution mentioned here on this issue, but it doesnt help

我有一个 java 项目,我将其重新配置为 Maven 项目。重新配置并添加所需的大部分依赖项后,我在运行mvn install命令时在控制台中收到以下错误。我在这个问题上尝试了这里提到的解决方案,但它没有帮助

Following are the console logs:

以下是控制台日志:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building FlockHydraAutomation 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ FlockHydraAutomation ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ FlockHydraAutomation ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 15 source files to C:\Maven\FlockHydra-Automation\FlockHydraAutomation\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.249 s
[INFO] Finished at: 2017-09-23T13:44:15+05:30
[INFO] Final Memory: 10M/220M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project FlockHydraAutomation: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

POM File:

POM文件:

<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>com.Flock</groupId>
    <artifactId>FlockHydraAutomation</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>FlockHydraAutomation</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <sourceDirectory>flockWebclient</sourceDirectory>
        <resources>
            <resource>
                <directory>resources</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Attached is the screenshot of the Java Compiler: Java Compiler

附上Java编译器截图: Java Compiler

回答by ranjithkr

Based on your comment on the previous answer looks like you are indeed pointing to a JDK. So now can you try this, Open Eclipse and goto Windows-> preferences -> Java -> installed JREs, and check if you are pointing to a JRE. If yes, change the path to your JDK and try to run a Maven build again. Hopefully this helps resolve the issue.

根据您对上一个答案的评论,您似乎确实在指向 JDK。所以现在你可以试试这个,打开 Eclipse 并转到 Windows-> 首选项 -> Java -> 已安装的 JRE,然后检查您是否指向 JRE。如果是,请更改 JDK 的路径并尝试再次运行 Maven 构建。希望这有助于解决问题。

回答by SilverNak

You have to make sure, your JAVA_HOMEenvironment variable points to a JDK (not a JRE), as the error mentions.

JAVA_HOME正如错误所述,您必须确保您的环境变量指向 JDK(而不是 JRE)。

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

[错误] 此环境中未提供编译器。也许您在 JRE 而不是 JDK 上运行?

Execute mvn -version. The output will show, what directory JAVA_HOME point to. Then make sure, this is a JDK by setting the JAVA_HOMEvariable to a JDK path.

执行mvn -version。输出将显示 JAVA_HOME 指向的目录。然后通过将JAVA_HOME变量设置为 JDK 路径来确保这是一个 JDK 。

回答by raphaeljuwe

I had the same issue, followed the recommendations stated above, but the issued persist.

我遇到了同样的问题,遵循了上述建议,但问题仍然存在。

below was my pom.xml

下面是我的 pom.xml

<build>
<plugins>
    <plugin>  
       <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.4</version>
        <configuration> 
            <source>1.8</source>
            <target>1.8</target>
            <fork>true</fork>
     <executable>C:\Program Files\Java\jdk\bin\javac</executable>
        </configuration>
        <executions>
            <execution>
                <id>tomcat-run</id>
                <goals>
                    <goal>exec-war-only</goal>
                </goals>
                <phase>package</phase>
                <configuration>
                    <path>/</path>
                    <attachartifactclassifier>exec-war</attachartifactclassifier>
                    <attachartifactclassifiertype>jar</attachartifactclassifiertype>
                </configuration>
            </execution>
                <execution>
      <goals>
        <goal>spring-boot:run</goal>
      </goals>

    </plugin>

</plugins>

To fix the issue, do use this pom.xml

要解决此问题,请使用此 pom.xml

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

</plugins>

Attached is the snapshot of my IDE .

附件是我的 IDE 的快照。

image snapshot

图像快照

回答by gscott4

I was having the same error and it turned out to be an issue with the .classpath file for me:

我遇到了同样的错误,结果证明是 .classpath 文件的问题:

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>

The attribute pointing to the "/WEB-INF/lib" folder was missing in my case.

在我的情况下,指向“/WEB-INF/lib”文件夹的属性丢失。