javamavenubuntujavadocmaven-javadoc-plugin

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


When I try to execute the command

mvn clean javadoc:jar package

it shows

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.

I checked out the already asked question Unable to find javadoc command - maven and the solution I tried above were taken from this solution only. I am new to Ubuntu. How can I fix this?

Whereas when I run echo $JAVA_HOME it prints:

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

I also tried setting the JAVA_HOME to:

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

When I run mvn -v, it prints:

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"

And when I run echo $JAVA_HOME it prints:

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

Solution

  • I would remove the above listed packages with pattern openjdk-11-.* (see this question) and install Java like this.