Reputation: 9793
I ran this command in my project directory to build and package it:
mvn clean javadoc:jar package
I do have my JAVA_HOME
variable set correctly.
Evidently:
$ which java
/usr/bin/java
$ sudo ls -l /usr/bin/java
lrwxr-xr-x 1 root wheel 74 Dec 18 23:42 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
$ which javadoc
/usr/bin/javadoc
Does anyone know why mvn still complains?
Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.8:jar (default-cli) on project foo_bar: MavenReportException: Error while creating archive: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set. -> [Help 1]
Upvotes: 59
Views: 88815
Reputation: 9669
While a lot of answers talk about OS X, for a Debian or Debian-like system (such as Ubuntu), I've decided to abuse the "alternatives" system:
export JAVA_HOME=$(update-alternatives --query javadoc | grep Value: |
head -n1 | sed 's/Value: //' | sed 's@bin/javadoc$@@')
Rewriting that more cleanly with awk
, or using a more correct way to access the value in the "alternatives" database, is left as an exercise for the reader.
Alternatively, given that the point of using "alternatives" system is to maintain symlinks such as /usr/bin/javadoc
in this case, we can just query the path pointed to by the symlink:
export JAVA_HOME=$(realpath /usr/bin/javadoc | sed 's@bin/javadoc$@@')
While this isn't the only possible "Java home" (you might have numerous JDKs installed), given that I only care about moving the mvn
build forward, and the error talks about Javadoc, I chose to refer to this the directory containing the javadoc
binary.
Don't forget to install a JDK in addition to a JRE. For instance, the JDK I needed was openjdk-11-jdk
, to complement the JRE openjdk-11-jre
which I previously installed.
After the above, the JAVA_HOME
envvar has this value on my system: /usr/lib/jvm/java-11-openjdk-amd64/
Upvotes: 9
Reputation: 2571
I started facing this issue once I switched to using sdkman and removed Ubuntu's java packages. Everything else works fine, but the javadoc plugin fails when using IntelliJ IDEA's bundled maven. Thankfully, we can set environment variables at a per project level in
Build, Execution, Deployment > Build Tools > Maven > Runner
In the Environment variables: text box, add
JAVA_HOME=/home/user/.sdkman/candidates/java/11.0.12-open/
Upvotes: 0
Reputation: 2322
You can make it use the java.home system property instead of the JAVA_HOME environment variable:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</configuration>
</plugin>
Source of idea: https://medium.com/@kankvish/fixing-issue-the-environment-variable-java-home-is-not-correctly-set-b5f0b66a84d0
Upvotes: 49
Reputation: 738
Upgrade maven-javadoc-plugin plugin to latest version (3.3.0 or later).
Upvotes: 2
Reputation: 1741
There are 2 options to fix this. Here are the steps:
Make sure to configure JAVA_HOME as an environment variable.
Option 1: Add javadocExecutable into properties.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>${project.build.sourceEncoding
</project.reporting.outputEncoding>
<java.version>11</java.version>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</properties>
Option 2: Add javadocExecutable into the build section as below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
<configuration>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
<excludePackageNames>com.vu.poc.test.objects</excludePackageNames>
<overview />
</configuration>
</plugin>
Upvotes: 6
Reputation: 1393
You can add the JAVA_HOME as an environment variable in eclipse.
Go to your maven build-> add the following.
Click New->
Name: JAVA_HOME
Value : your path here.
This worked for me!
Upvotes: 14
Reputation: 2788
After spending 2-3 hours of time, i felt opening Eclipse via command line looks easiest solution. Follow below steps,
cd <Folder_where_Eclipse.app>
open Eclipse.app
Now your eclipse can able to find the Terminal Environmental variables.
Upvotes: 4
Reputation: 1541
They fixed this for OSX in maven 3.1 by adding "export JAVA_HOME" to the "bin/mvn" shell script, obviating the need to set JAVA_HOME externally yourself just to find javadoc.
Upvotes: 0
Reputation: 188024
A correct which java
is not evidence enough, since /usr/bin/
will likely be in your PATH
anyway. Check
$ echo $JAVA_HOME
for evidence. Or run
$ JAVA_HOME=/path/to/your/java/home mvn clean javadoc:jar package
On OS X you can set your JAVA_HOME
via:
$ export JAVA_HOME=$(/usr/libexec/java_home)
which on my machine points to
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Upvotes: 60