Maven not finding JavaDoc command


This is similar to a much older report of an error (, but I would like to find the proper way to address this in IntelliJ IDEA 2020.3. 

When trying to build a project using Maven and generating javadocs with the javadoc:javadoc goal, the maven run is failing with 

"Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.2.0:javadoc (default-cli) on project ContAnalysis: An error has occurred in Javadoc report generation: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set."

This happens when I launch IDEA from the GUI using the finder or other programs like LaunchBar. It does not happen if I launch IDEA from the command line. The build works perfectly if I run mvn from the command line. 

I assume this means the JAVA_HOME variable is not set during the mvn run. Why is IDEA failing to pick this up properly? 

The Build, Execution, Deployment > Build Tools > Maven > Runner setting is set to Use Project JDK, which points to a jdk containing a bin/javadoc command which can be run properly. 

Adding the following to the below configuration does not solve the issue


Nor does setting the executable to an absolute path work. Something else must be wrong with the setting which IDEA is providing to mvn. Very puzzling. 

Comment actions Permalink

Setting environment variables on macOS so that it's visible to all the apps is tricky, please see

Comment actions Permalink

Is there are reason why IntelliJ does not pick this up from the users command line profile? 

It is weird that even with the javadoc executable path set directly in the Maven configuration it is not working. It is as though something else is depending on JAVA_HOME or java.home being set properly. 

Comment actions Permalink

This is the way OS handles environment variables. Not sure why it doesn't work with the explicit path, likely there is some issue with the Maven plug-in configuration.

Comment actions Permalink

I had a look at the stack overflow item and this is frankly very confusing. What do you suggest as the proper way to fix this for IntelliJ IDEA running on the new versions of MacOS X? 

It seems like it should work right out of the box, but if there is some standard launchctl or plist or something that we should be installing, that would be good to know.  

When just launched from the GUI, doing a package on any project of mine right now if producing the following error:

Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.2.0:jar (attach-javadocs) on project MClustFiles: MavenReportException: Error while generating Javadoc: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.

OTOH, when launched from the command line, there is no such issue. 

The following images are the settings on one of the projects. Fairly vanilla flavored for Maven and using jdk12. 


Comment actions Permalink

Did you try setting JAVA_HOME in environment.plist via launchctl?

Comment actions Permalink

Can you tell me exactly which file and what content for Mac OS 11.2.3 and the commands that need to follow? 

The StackOverflow link has a lot of detail for some other case. I think if this is going to be required normally for IntelliJ IDEA there should just be a standard recipe to install. 

Comment actions Permalink

The answer already contains all the details you need and should work on Mac OS 11.2.3 as well.

Comment actions Permalink

Thanks for the temporary fix. The following ~/Library/LaunchAgents/environment.plist file does seem to work after doing a 'launchctl load ~/Library/LaunchAgents/environment.plist' command. 

But while this works as a sort of hack, why is it necessary? Why isn't IntelliJ IDEA using the path for the associated java development environment from the settings when maven is run?

It seems quite ugly to have the user have to embed the chosen JDK into a system file. And how confusing will this be after the user has done this and then chooses a Java 8 JDK and wants to use the options for that in a few months and has possibly forgotten about the system file. 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home
Comment actions Permalink

If you unset JAVA_HOME in your system so that it's not visible from the terminal environment as well and use javadocExecutable plug-in configuration instead, will it work from the command line Maven outside of IntelliJ IDEA?

If not, it's a problem of the Maven plug-in, not IntelliJ IDEA.

As for why environment is different for console and GUI apps on macOS and why it's so hard to set it you can ask Apple support.

Comment actions Permalink

In IntelliJ IDEA you can set JAVA_HOME for Maven here so that you don't need to adjust your system environment:

Or set it directly in the specific Maven run configuration.

Comment actions Permalink

In answer to the query, I unset JAVA_HOME and added the following to the pom file. When I did that, it will package properly from the command line producing the javadocs. So I guess the answer is yes and it is not a problem with the maven plug-in? 

Comment actions Permalink

Does it fail if you remove javadocExecutable configuration?

Comment actions Permalink

No. From the command line, without a JAVA_HOME set, mvn package works and builds the javadocs. 

'javadoc --version' gives javadoc 12.0.2 and 'which javadoc' gives /usr/bin/javadoc. 

'/usr/libexec/java_home' gives /Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home. 

So the default java being used on this machine is jdk12. 

Comment actions Permalink

I should also note that the command line is using a homebrew installed version of maven. 

mvn --version gives 

Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T11:41:47-07:00)
Maven home: /usr/local/Cellar/maven/3.6.0/libexec
Java version: 12.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

Comment actions Permalink

So it's still an issue with environment difference for GUI and console apps on macOS.

Either set the environment globally per SO answer or set it in IntelliJ IDEA for Maven. Simple as that.

Comment actions Permalink

I guess I am still having a hard time understanding this. I don't think I am an atypical user so this strikes me as unnecessarily complicated. 

What differences are you referring to here as being responsible? 

On the command line, without a JAVA_HOME set explicitly, the mvn package works as expected and builds the javadocs. 

With IntelliJ normally installed and without the environment.plist file, and without an explicit JAVA_HOME set for the Maven runner, it does not generate the javadoc correctly. 

When there is no explicit JAVA_HOME set for the Maven runner, why doesn't IntelliJ IDEA just use the home path for the JDK chosen for the project? That strikes me as more what the user would expect. The JDK is set, use the javadoc from that JDK unless told explicitly otherwise.

Why does there need to be an explicit JAVA_HOME set in the environment?

Comment actions Permalink

To answer this question you need to debug maven-javadoc-plugin and see how it finds the location of javadoc. Then find what's different when it's run from IntelliJ IDEA and from the terminal which affects this plug-in configuration. Then fix the environment so that it's the same and plug-in can work properly in both cases.

Comment actions Permalink

OK, so how does one get the exact way that maven is being invoked by IntelliJ IDEA? The environment and all command line settings? 

Comment actions Permalink

Environment is inherited automatically from the parent process (IntelliJ IDEA itself). Unless you override it via the Maven Runner configuration in IntelliJ IDEA.

ps -auxww will show you the exact command line of the Maven process started by IntelliJ IDEA.

Not sure how to mimic this behavior, you probably need some GUI app to start Maven from so that it uses macOS environment for GUI apps and not the terminal apps which is different for some unknown reason on this system while it's the same on Windows.


Please sign in to leave a comment.