简体   繁体   English

Maven 包错误:此环境中没有提供编译器

[英]Maven package error: No compiler is provided in this environment

I am new to Maven and I am trying to create a JAR out of a HelloWorld program.我是 Maven 的新手,我正在尝试从 HelloWorld 程序中创建一个 JAR。

I have done the classpath setting:我已经完成了类路径设置:

在此处输入图片说明

This is the pom.xml file:这是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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.demo</groupId>
  <artifactId>custom-project</artifactId>
  <packaging>maven-plugin</packaging>
  <version>1.0</version>
  <name>custom-project Maven Mojo</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>2.0</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

When I trigger mvn package command, I am getting this error:当我触发mvn package命令时,出现此错误:

[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.700 s
[INFO] Finished at: 2018-04-13T12:25:12+05:30
[INFO] Final Memory: 9M/155M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project custom-project: Compilation f
ailure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR]
[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

JAVA_HOME is already set as C:\\Program Files\\Java\\jdk1.8.0_121\\bin in classpath . JAVA_HOME已在classpath设置为C:\\Program Files\\Java\\jdk1.8.0_121\\bin Please suggest how to resolve this issue.请建议如何解决此问题。

Your JAVA_HOME is set to a JRE not to a JDK .您的JAVA_HOME设置为JRE而不是JDK The JRE does not include the Java Compiler, so set JAVA_HOME to a JDK and it should work JRE不包括 Java 编译器,因此将JAVA_HOME为 JDK,它应该可以工作

Also you can goto your project properties-> Libraries-> add Library -> JRE system Library -> Alternate JRE -> Add.您也可以转到您的项目属性-> 库-> 添加库-> JRE 系统库-> 备用 JRE -> 添加。 and then you choose your JDK path from your system and apply.然后从系统中选择 JDK 路径并应用。 Make sure to remove JRE From project library.确保从项目库中删除 JRE。

In my case, this works well.就我而言,这很有效。

You need to tell java what class to run.你需要告诉java要运行什么类。 Depending on the maven plugin you use the ways might be different.根据您使用的 Maven 插件,方式可能会有所不同。 This link shows how it can be done with the help of the maven-assembly-plugin https://stackoverflow.com/a/45902851/6825678此链接显示了如何在 maven-assembly-plugin https://stackoverflow.com/a/45902851/6825678的帮助下完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Eclipse/Maven 错误:“此环境中未提供编译器” - Eclipse/Maven error: "No compiler is provided in this environment" Maven(命令行):此环境不提供编译器 - Maven (commandline): No compiler is provided in this environment Jenkins [ERROR]在此环境中未提供编译器 - Jenkins [ERROR] No compiler is provided in this environment Jenkins Maven项目在此环境中未提供编译器 - Jenkins Maven project no compiler is provided in this environment Yosemite上的Maven安装失败:此环境中未提供编译器 - Maven installation failure on Yosemite: No compiler is provided in this environment mvn clean package error: 此环境没有提供编译器。 也许您在 JRE 而不是 JDK 上运行? - mvn clean package error: No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? 此环境中未提供编译器。 - Eclipse - Maven - java-8-openjdk - Xubuntu - No compiler is provided in this environment. - Eclipse - Maven - java-8-openjdk - Xubuntu 此环境中不提供编译器。 执行 mvn clean package 时 - No compiler is provided in this environment. When execute mvn clean package jenkins 在这个环境中没有提供编译器 - No compiler is provided in this environment with jenkins Maven 尝试使用命令行在 Linux 环境中编译:此环境中未提供编译器 - Maven Trying to compile in Linux environment using command line : No compiler is provided in this environment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM