簡體   English   中英

無法執行目標org.apache.maven.plugins:maven-compiler-plugin:3.5.1:在項目上編譯(default-compile)

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

我有一個java項目,我重新配置為Maven項目。 在重新配置並添加所需的大多數依賴項之后,當我運行mvn install命令時,我在控制台中收到以下錯誤。 我在這個問題上嘗試了這里提到的解決方案,但它沒有幫助

以下是控制台日志:

[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文件:

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

附件是Java Compiler: Java Compiler的屏幕截圖

根據您對上一個答案的評論,您確實指向了JDK。 所以現在可以嘗試這個,打開Eclipse並轉到Windows-> preferences - > Java - >安裝JRE,並檢查是否指向JRE。 如果是,請更改JDK的路徑並嘗試再次運行Maven構建。 希望這有助於解決問題。

您必須確保,您的JAVA_HOME環境變量指向JDK(而不是JRE),因為錯誤提到了。

[錯誤]此環境中未提供編譯器。 也許您運行的是JRE而不是JDK?

執行mvn -version 輸出將顯示JAVA_HOME指向的目錄。 然后通過將JAVA_HOME變量設置為JDK路徑來確保這是一個JDK。

我有同樣的問題,遵循上面提到的建議,但發布仍然存在。

下面是我的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>

要解決此問題,請使用此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>

附件是我的IDE的快照。

圖像快照

我遇到了同樣的錯誤,結果證明我的.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>

我的案例中缺少指向“/ WEB-INF / lib”文件夾的屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM