-1

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
VIAGC
  • 639
  • 6
  • 14
  • this is my maven : mvn -v java path `Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre` so try to update java path with `/jre` at the end and tell me if it worked. – Mohamed Bdr Mar 19 '21 at 08:13
  • @MohamedBdr By doing that I get the error I mentioned initially. – VIAGC Mar 19 '21 at 08:15
  • @ThunderKnight Have you installed Java via a packet manager? – Janez Kuhar Mar 19 '21 at 08:19
  • @JanezKuhar I have installed it with the help of terminal – VIAGC Mar 19 '21 at 08:20
  • It may be that you've installed [`openjdk-11-jre`](https://packages.ubuntu.com/bionic/java/openjdk-11-jre) instead of [`openjdk-11-jdk`](https://packages.ubuntu.com/bionic/java/openjdk-11-jdk). – Janez Kuhar Mar 19 '21 at 08:25
  • How do I check whether I have `openjdk-11-jre` or `openjdk-11-jdk` – VIAGC Mar 19 '21 at 08:27
  • @JanezKuhar What do you get after running `java -version` – VIAGC Mar 19 '21 at 08:28
  • try this command too `sudo apt list --installed | grep -i openjdk` – Mohamed Bdr Mar 19 '21 at 08:29
  • I get ```WARNING: apt does not have a stable CLI interface. Use with caution in scripts. openjdk-11-jdk-headless/focal-updates,focal-security,now 11.0.10+9-0ubuntu1~20.04 amd64 [installed,automatic] openjdk-11-jdk/focal-updates,focal-security,now 11.0.10+9-0ubuntu1~20.04 amd64 [installed,automatic] openjdk-11-jre-headless/focal-updates,focal-security,now 11.0.10+9-0ubuntu1~20.04 amd64 [installed,automatic] openjdk-11-jre/focal-updates,focal-security,now 11.0.10+9-0ubuntu1~20.04 amd64 [installed,automatic] ``` – VIAGC Mar 19 '21 at 08:31
  • can you try this `JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/jre/bin` and don't forget to use `source ~/.bash_profile` and please tell me did you use bashrc or bash_profile ? – Mohamed Bdr Mar 19 '21 at 08:39
  • @Mohamed `source ~/.bash_profile` to use this command where? Also, I don't know about about `bashrc`, I used this link to download https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-on-ubuntu-18-04 – VIAGC Mar 19 '21 at 08:42
  • alright so you set here all the environment variables to `/etc/environment` so you need to run `source /etc/environment` every time you make a change so please try to update your java path to /jre/bin and then you must run `source /etc/environment` and then try mvn again – Mohamed Bdr Mar 19 '21 at 08:48
  • @MohamedBdr Sorry, but can you please give the commands as an answer, will really appreciate it, I am not very well used to ubuntu – VIAGC Mar 19 '21 at 08:51
  • no problem 1- `sudo nano /etc/environment` 2- `JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/jre/bin"` 3- `source /etc/environment` 4- `mvn clean javadoc:jar package` – Mohamed Bdr Mar 19 '21 at 08:53
  • @MohamedBdr I did this what should I set PATH variable now? – VIAGC Mar 19 '21 at 09:03
  • `export PATH=$PATH:/usr/lib/jvm/java-11-openjdk-amd64/bin` you need to insert that inside your bash profile `vi ~/.bash_profile` and please tell me what `echo $PATH` shows – Mohamed Bdr Mar 19 '21 at 09:09
  • and did you have `/usr/java` path or not `cd /usr/java` – Mohamed Bdr Mar 19 '21 at 09:10
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/230117/discussion-between-thunderknight-and-mohamed-bdr). – VIAGC Mar 19 '21 at 09:11

3 Answers3

1

Hmm..., probably the file doesn’t exist for running javadoc. Does the file /usr/lib/jvm/java-11-openjdk-amd64/bin/javadoc exist?

Please try:

sudo apt install openjdk-11-jdk
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CKey
  • 88
  • 5
0

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

Janez Kuhar
  • 3,705
  • 4
  • 22
  • 45
0

On my Mac (big Sur) I was getting the same problem. After reading this article ; this command worked for my enviroment:

export JAVA_HOME=$(/usr/libexec/java_home)
Baron_Samedi
  • 487
  • 4
  • 8