运行 "mvn clean javadoc:jar package" 上的错误 "the JAVA_HOME environment variable is not defined correctly"

Error "the JAVA_HOME environment variable is not defined correctly" on running "mvn clean javadoc:jar package"

当我尝试执行命令时

mvn clean javadoc:jar package

显示

the JAVA_HOME environment variable is not defined correctly. This environment variable is needed to run this program.

NB: JAVA_HOME should point to a JDK, not a JRE.

我查看了已经提出的问题Unable to find javadoc command - maven,我上面尝试的解决方案仅取自此解决方案。我是 Ubuntu 的新手。我该如何解决这个问题?

而当我 运行 echo $JAVA_HOME 它打印:

/usr/lib/jvm/java-11-openjdk-amd64

我还尝试将 JAVA_HOME 设置为:

  1. /etc/launchd.conf/java-11-openjdk-amd64
  2. /usr/libexec/java-11-openjdk-amd64
  3. /usr/libexec/java-11-openjdk-amd64/

当我 运行 mvn -v 时,它打印:

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.10, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "5.8.0-45-generic", arch: "amd64", family: "unix"

当我 运行 echo $JAVA_HOME 它打印:

/usr/lib/jvm/java-11-openjdk-amd64

我会删除 with pattern openjdk-11-.* (see this question) and install Java

嗯...,可能 运行 javadoc 的文件不存在。文件 /usr/lib/jvm/java-11-openjdk-amd64/bin/javadoc 是否存在?

请尝试:

sudo apt install openjdk-11-jdk

在我的 Mac(大苏尔)上,我遇到了同样的问题。看完这篇 article ;此命令适用于我的环境:

export JAVA_HOME=$(/usr/libexec/java_home)