【问题标题】:Compilation error in building maven project构建maven项目时出现编译错误
【发布时间】:2018-07-10 05:30:39
【问题描述】:

我们正在尝试构建一个 Maven 工件并将其部署到 Jenkins 的 Nexus Repository Manager 中,但是在构建过程中我们遇到了编译错误。 这是我们得到的错误。!

ERROR] 未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile 项目studentapp上的(默认编译):编译失败错误]否 在这个环境中提供了编译器。也许你正在运行 JRE而不是JDK? [错误] 编译错误:[信息] -------------------------------------------------- ------------ [错误] 此环境中未提供编译器。也许你正在跑步 在 JRE 而不是 JDK 上?

这是我们的 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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.jdevs</groupId>
  <artifactId>studentapp</artifactId>
  <version>2.5-SNAPSHOT</version>
  <packaging>war</packaging>

  <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <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>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
   <distributionManagement>
        <repository>
            <id>deployment</id>
            <name>Internal Releases</name>
            <url>http://rig.eastus.cloudapp.azure.com:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>deployment</id>
            <name>Internal Snapshot Releases</name>
            <url>http://rig.eastus.cloudapp.azure.com:8081/repository/maven-snapshots/</url>
        </snapshotRepository> 
    </distributionManagement>
  <dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.5.1</version>
      <type>maven-plugin</type>
    </dependency>

    <dependency>
      <groupId>commons-httpclient</groupId>
      <artifactId>commons-httpclient</artifactId>
      <version>3.1</version>
    </dependency>

    <dependency>
      <groupId>org.apache.jackrabbit</groupId>
      <artifactId>jackrabbit-webdav</artifactId>
      <version>1.5.0</version>
    </dependency>

    <dependency>
      <groupId>org.sonatype.sisu</groupId>
      <artifactId>sisu-guice</artifactId>
      <version>2.1.7</version>
      <type>pom</type>
    </dependency>

    <dependency>
      <groupId>javax.inject</groupId>
      <artifactId>javax.inject</artifactId>
      <version>1</version>
    </dependency>

    <dependency>
      <groupId>aopalliance</groupId>
      <artifactId>aopalliance</artifactId>
      <version>1.0</version>
    </dependency>

    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>3.5.0</version>
    </dependency>

    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-artifact</artifactId>
      <version>3.5.0</version>
    </dependency>

    <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>3.5.1</version>
      <scope>provided</scope>
    </dependency>


  </dependencies>
</project>

【问题讨论】:

  • 愚蠢的问题,但是你的 jenkins 实例上安装了 JDK 和 maven + 设置 PATH 变量
  • @lvthillo 没有愚蠢的问题。错误消息甚至询问Perhaps you are running on a JRE rather than a JDK

标签: maven jenkins maven-2 nexus nexus3


【解决方案1】:

重新配置您的 Jenkins 。从主页转到管理插件,然后转到全局工具配置。使用 JDK 文件夹的正确路径重新初始化 JAVA_HOME 字段。

【讨论】:

    【解决方案2】:

    您需要在 Jenkins 配置中定义 JDK 安装路径。此外,如果您使用主从配置,则需要确保特定的 JDK 安装(在同一位置)与 Jenkins 配置中定义的相同。 ANT 和 Maven 安装也是如此。

    【讨论】:

      【解决方案3】:

      至少有两个其他来源表明,对于远程代理,您需要为java.home 创建一个环境变量在节点配置中 指向JAVA_HOME 目录(不仅仅是%JAVA_HOME% 或类似的)。

      导航至:Jenkins &gt; Manage Jenkins &gt; Manage Nodes 并单击远程节点旁边的配置图标。从那里,向下滚动到节点属性,勾选 Environment Variables 框并定义 java.home 作为名称和 JDK 的路径作为值,例如c:\Program Files\Java\jdk1.8.0_181

      这是我最终需要做的,即使在构建代理服务器上发现所有系统环境变量都正确并且java -versionjavac -version 都正确报告之后。

      我意识到 OP 没有指定 Master 或 Remote,但希望这对偶然发现此问答的人有所帮助。

      此来源提供了第一个线索但没有解释:https://www.pgs-soft.com/blog/oops-jenkins-slave-maven-not-working/

      我无法找到在谷歌搜索时发现的有关此修复的其他提及。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-27
        • 2020-07-06
        • 2019-08-07
        • 1970-01-01
        • 2020-10-21
        • 1970-01-01
        相关资源
        最近更新 更多