14

I'm trying to run the maven verify command but getting this error.

MavenReportException: Error while generating Javadoc: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.

Maven cannot find the javadoc command so it cannot create the documentation.

The interesting part is that I can run the mvn javadoc:jar command and it successfully works. Besides my JAVA_HOME is points to the correct location.

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home

This is from the pom file.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>3.0.0-M1</version>
    <configuration>
        <additionalparam>-Xdoclint:none</additionalparam>
    </configuration>
    <executions>
        <execution>
              <id>attach-javadoc</id>
              <phase>verify</phase>
              <goals>
                 <goal>jar</goal>
              </goals>
        </execution>
    </executions>
</plugin>

Please don't tell me this is the duplicate of the question Unable to find javadoc command - maven. I know the problem is the same but our situations are different and my JAVA_HOME points to the right location. So that solution doesn't work for me.

amone
  • 3,712
  • 10
  • 36
  • 53
  • Is there a good reason why are you using maven-java-plugin version 3.0.0-M1 instead of `3.0.0`? Furthermore which Maven version do you use? Can you also show the full pom file? – khmarbaise Mar 25 '18 at 10:55
  • MavenReportException: Error while generating Javadoc: Unable to find javadoc command: The javadoc executable '/Library/Java/JavaVirtualMachines/jdk-12.0.2+10/Contents/Home/../bin/javadoc' doesn't exist or is not a file. Verify the parameter – Oleksii Kyslytsyn Jul 25 '19 at 15:55

2 Answers2

17

I had this same issue with java 9.0.4 and macOs, and adding the following configuration in maven-javadoc-plugin solved it for me

  <configuration>
     .....
     <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
  </configuration>
Aleksandr Dubinsky
  • 22,436
  • 15
  • 82
  • 99
miskender
  • 7,460
  • 1
  • 19
  • 23
  • 4
    Wow, that's bullshit. When the error message says to make sure `JAVA_HOME` is set correctly (and it is!) and you still need to modify the `.pom` file in one of the libraries... grrr. Whatever, your answer worked for me on Ubuntu, too. Thanks! – mozzbozz Apr 02 '19 at 20:57
  • Thanks a lot! Solved my issue on Windows as well. Why is that not set by default rather than using JAVA_HOME from os?? – Tiemo Vorschütz Dec 15 '20 at 12:23
  • 1
    This also fixed my issue on Windows using IntelliJ. I even double checked the JAVA_HOME environment variable within the maven settings in the IntelliJ settings. Very frustrating. – Sleepybear May 18 '21 at 23:06
12

For JDK versions 1.8, 9, 11, 12, 14, 15, 16, 17:

<build>
    <plugins>
        <!-- ... -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <!--<version>3.2.0</version>-->
            <configuration>
                <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
                <!--<doclint>none</doclint>-->
            </configuration>
        </plugin>
        <!-- ... -->
    </plugins>
</build>
Oleksii Kyslytsyn
  • 2,458
  • 2
  • 27
  • 43