我有一个java项目,我重新配置为Maven项目。在重新配置并添加所需的大多数依赖项后,我在运行mvn install
命令时在控制台中收到以下错误。我尝试了this issue上提到的解决方案,但它没有帮助
以下是控制台日志:
[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编译器的屏幕截图: Java Compiler
答案 0 :(得分:6)
根据您对上一个答案的评论,看起来您确实指向了JDK。 那么现在可以试试这个,Open Eclipse并转到Windows-&gt;偏好 - &gt; Java - &gt;安装了JRE,并检查是否指向了JRE。如果是,请更改JDK的路径并尝试再次运行Maven构建。希望这有助于解决问题。
答案 1 :(得分:2)
您必须确保,您的JAVA_HOME
环境变量指向JDK(而不是JRE),因为错误提到了。
[错误]此环境中未提供编译器。也许你是在运行JRE而不是JDK?
执行mvn -version
。输出将显示JAVA_HOME指向的目录。然后通过将JAVA_HOME
变量设置为JDK路径来确保这是一个JDK。
答案 2 :(得分:0)
我遇到了同样的问题,遵循了上述建议,但是问题仍然存在。
下面是我的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的快照。
答案 3 :(得分:0)
我遇到了同样的错误,事实证明这是.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”文件夹的属性。