简体   繁体   English

MavenReportException:JAVA_HOME 设置不正确

[英]MavenReportException: JAVA_HOME not correctly set

I've tried many JDK versions in order to solve this problem but it seems no matter which java i'm using the outcome is always the same.我已经尝试了很多 JDK 版本来解决这个问题,但似乎无论我使用哪个 java 结果总是一样的。

MavenReportException: Error while creating archive: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set. MavenReportException:创建存档时出错:无法找到 javadoc 命令:未正确设置环境变量 JAVA_HOME。

Debug调试

These are the jdk's currently installed:这些是当前安装的 jdk: 在此处输入图像描述

I ran:我跑了:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

export PATH=$JAVA_HOME/bin:$PATH

java -version : java -version

openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~20.04-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)

javac -version

javac 1.8.0_265

mvn clean deploy -P release mvn clean deploy -P 发布

在此处输入图像描述

MavenReportException: Error while creating archive: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set. MavenReportException:创建存档时出错:无法找到 javadoc 命令:未正确设置环境变量 JAVA_HOME。

Maven Plugin Configuration Maven 插件配置

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <executable>${JAVA_HOME}/bin/javac</executable>
    </configuration>
</plugin>

Although which java and which javadoc pointing to /usr/bin could that be the issue?虽然which javawhich javadoc pointing to /usr/bin这可能是问题所在?

Edit 1编辑 1

Contents of /bin /bin的内容

在此处输入图像描述

I don't know if this helps, but in my case maven Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.2.0:jar and gave an exception: MavenReportException: Error while generating Javadoc: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.我不知道这是否有帮助,但在我的情况下 maven Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.2.0:jar并出现异常: MavenReportException: Error while generating Javadoc: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.

The solution was to find the plugin that was causing the issue, <artifactId>maven-javadoc-plugin</artifactId> in my case and add the following:解决方案是找到导致问题的插件,在我的例子中是<artifactId>maven-javadoc-plugin</artifactId>并添加以下内容:

                <configuration>
                    <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
                </configuration>

where ${java.home} was /usr/lib/jvm/java-11-openjdk-amd64/ .其中${java.home}/usr/lib/jvm/java-11-openjdk-amd64/

The plugin looked like:该插件看起来像:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
                </configuration>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

and the goal was executed successfully.并成功执行了目标。

Please check the java version for Maven using the following command:请使用以下命令检查 Maven 的 java 版本:

#mvn --version #mvn --版本

It will give something like:它会给出类似的东西:

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T01:19:05+05:30) Maven home: /home/user/apache-maven-3.5.3 Java version: 1.8.0_121, vendor: Oracle Corporation Java home: /home/user/jdk1.8.0_121/jre Default locale: en_IN, platform encoding: UTF-8 Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T01:19:05+05:30) Maven home: /home/user/apache-maven-3.5.3 Java version: 1.8.0_121, vendor: Oracle Corporation Java home : /home/user/jdk1.8.0_121/jre 默认语言环境:en_IN,平台编码:UTF-8

Here, you can see which JAVA version is used and its location.在这里,您可以看到使用了哪个 JAVA 版本及其位置。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM