我正在使用m2eclipse在Eclipse中编译一个项目。我在Eclipse中设置JDK路径,如下所示:

Windows-->preferences-->installed jres--> jdk1.7.xx  path

但是这显示了一个错误

[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.424s
[INFO] Finished at: Tue Oct 29 15:21:01 IST 2013
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-   plugin:3.1:compile (default-compile) on project TEST-WEB: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

当前回答

试试这个。

<build>
...
    <plugins>
    ...
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <fork>true</fork>
                <executable> path to jdk \bin\javac.exe</executable>
            </configuration>
        </plugin>
    </plugins>
</build>

其他回答

我有同样的问题,我只是添加JAVA_HOME环境变量。

如果您正在使用eclipse,请参考https://stackoverflow.com/a/21279068/6097074 如果您使用的是intellij,只需在添加JAVA_HOME后从项目目录打开命令提示符并运行mvn clean install(不要使用intellij终端)。

我有办法了。

这个问题最常见的解决方案是将jdk位置更改为我的Installed JREs而不是JRE位置,但这一次并没有解决我的问题。

所以我做了下面的事情来解决这个问题。 展开Installed JREs选项卡,您将发现一个Execution environments选项卡。

单击您最喜欢的执行环境。我用的是JAVASE-1.8。这里显示了两个选项。JDK和JRE。选择JDK,问题就解决了。

我也遇到了同样的问题,我犯的错误是我只在路径var中添加了jre路径,而不是jdk路径。当jdk路径添加到路径并构建maven项目时,它的工作完美。谢谢

试试这个。

<build>
...
    <plugins>
    ...
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <fork>true</fork>
                <executable> path to jdk \bin\javac.exe</executable>
            </configuration>
        </plugin>
    </plugins>
</build>

对我来说,我已经升级到大苏尔Mac操作系统,我必须删除这个,然后它就可以正常工作了。

sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin