JDK8 - Error "class file for javax.interceptor.InterceptorBinding not found" when trying to generate javadoc using Maven javadoc plugin
Asked Answered
K

10

94

I am using JDK8 (tried it on my Eclipse workspace with Win x64 u25 JDK + on Linux launched by Jenkins - jdk-8u20-linux-x64, same problem for both).

I have multi-module Maven project (I am launching Maven goal "javadoc:aggregate" from a main module with packaging type "pom").

Pom build section looks like this:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <configuration>
                <additionalparam>-Xdoclint:none</additionalparam>
            </configuration>
        </plugin>
    </plugins>
</build>

I always receive error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.10.1:aggregate (default-cli) on project uloan-global-build: An error has occurred in JavaDocs report generation:
[ERROR] Exit code: 1 - javadoc: error - com.sun.tools.doclets.internal.toolkit.util.DocletAbortException: com.sun.tools.doclets.internal.toolkit.util.DocletAbortException: com.sun.tools.doclets.internal.toolkit.util.DocletAbortException: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for javax.interceptor.InterceptorBinding not found
[ERROR] 
[ERROR] Command line was: /usr/java/jdk1.8.0_20/jre/../bin/javadoc @options @packages

I have tried everything possible and tried to search on Google for a long time, but no success. I have found links, where people had similar problems, but without any information about possible solution:

http://marc.info/?l=maven-user&m=139615350913286&w=2

http://mail-archives.apache.org/mod_mbox/maven-users/201409.mbox/%[email protected]%3E (suggesting to update JDK8 to > update 20, which I did, but problem is still the same).

Any hints or anyone experienced this kind of behavior as well (unfortunately it looks as quite "rare" problem for some reason)? Quite desperate about this...

Koller answered 6/1, 2015 at 23:0 Comment(3)
Are you certain you installed 8u20 correctly?Semicolon
I had the same problem with GRADLE - it was because I had JDK 1.7 on my path but JAVA_HOME was pointing at a 1.8 JDK - Thanks, @SemicolonMacaronic
I'm hitting the same thing but I am on 8u31Deimos
B
159

This appears to be due to javax.transaction.Transactional (or any other class in your classpath for that matter) being itself annotated with javax.interceptor.InterceptorBinding, which is missing in classpath unless explicitly declared in dependencies:

@Inherited
@InterceptorBinding // <-- this ONE is causing troubles
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Transactional {

Said that:

  • javax.transaction.Transactional - comes with javax.transaction:javax.transaction-api:1.+ (or org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.0.Final) and is typically used in JPA/ORM/JMS apps to annotate transactional methods.
  • javax.interceptor.InterceptorBinding - should come with javax.interceptor:javax.interceptor-api:1.+. But, although declared on top of Transactional, is not required for normal operation and (looks like because of this) is not getting fetched as a transitive dependency of your JPA framework.

As a result JDK8 javadoc tool fails to process the sources (if any of them are annotated with @Transactional).

Although it could be more specific about the place where this "error" has been found.

Issue fix: adding javax.interceptor:javax.interceptor-api:1.+ dependency fixes the issue.

<dependency>
    <groupId>javax.interceptor</groupId>
    <artifactId>javax.interceptor-api</artifactId>
    <version>1.2.2</version>
</dependency>

Note (January 2020): the latest (plausible) version is currently 1.2.2 (see https://mvnrepository.com/artifact/javax.interceptor/javax.interceptor-api

Bartonbartosch answered 27/2, 2015 at 0:44 Comment(6)
Yes, this solved a similar problem for me. Seems JDK 8’s javadoc requires transitive dependencies to be in the classpath whereas JDK 7 was more lenient.Aeronautics
The maven dependency is: <dependency> <groupId>javax.interceptor</groupId> <artifactId>javax.interceptor-api</artifactId> <version>1.2</version> </dependency>Mansuetude
Thanks a lot, @kozlovda, that solved it. Sorry for long delay with checking the answer - was working on something completely different in the meantime and couldn't find time to verify this in the old workspace :-)Koller
Thank you @Bartonbartosch this helped a lot :)Piselli
It's better to add it as an additionnal dependencies of maven-javadoc-plugin since the problem relies only in a conflict during javadoc generation process: <additionalDependencies> <additionalDependency> <groupId>javax.interceptor</groupId> <artifactId>javax.interceptor-api</artifactId> <version>1.2</version> </additionalDependency> </additionalDependencies>Transpontine
Isn't there a way to fix this for all the missing dependencies? I've started to add the dependencies, but then I keep getting the error with a next one, and a next one... So far: javax.interceptor-api, javax.ejb, javax.inject, javax.persistence, org.apache.commons.collections... it looks like a never ending story...Matriarchy
D
61

As @kozlovda already mentions, the issue comes with the @Transactional annotation (javax.transaction.Transactional).

If you have the described error on a Maven run for a Spring application, there is also another way to resolve the issue: Make sure not to use the the annotation from javax.transaction, instead use org.springframework.transaction.annotation.Transactional.

Replacing the import fixed the issue for me.

Docent answered 6/7, 2016 at 18:41 Comment(5)
Thanks! The javadoc for one of my controller classes always failed and I didn't saw directly why. It was the only class with an import on javax.Transactional.Audreaaudres
thanks, this is the right fix. If you are writing a spring application, you are supposed to use spring transactional, even if spring supports javax EJB transactional. And you are not supposed to mix the two different Transactional. I had the same issue with javadoc and I found out in one class out of thousands I had javax.transactional imported. Javadoc and this comment helped me out in finding the real mistake.Shcherbakov
This is a great answer and, I think, the right one for most of the cases. Usually you are using @Transactional in spring and so it just makes sense that you mistook the annotationCarpospore
This should be the correct answer and is the least intrusiveMangan
Great answer, solves the issue.Exponential
R
15

@lpratlong says in an answer supplied in a comment "add it as an additionnal dependencies of maven-javadoc-plugin". That worked for me, here's the full Maven plugin entry for impatient people like me to copy-paste:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <!-- <version>3.0.0</version> -->
            <configuration>
                <!-- Silence error javax.interceptor.InterceptorBinding not found -->
                <additionalDependencies>
                    <additionalDependency>
                        <groupId>javax.interceptor</groupId>
                        <artifactId>javax.interceptor-api</artifactId>
                        <version>1.2</version>
                    </additionalDependency>
                </additionalDependencies>
            </configuration>
        </plugin>

The version is commented out because in my case spring-boot manages the version, just restore as needed.

Riddick answered 19/12, 2017 at 14:54 Comment(2)
This is the best answer IMO because adding the dependency inside the plugin configuration makes it clear this dependency is needed by that plugin.Theism
Nice, addresses just the problem itself.Weevil
M
13

Use

import org.springframework.transaction.annotation.Transactional;

instead of

import javax.transaction.Transactional;

when you are using @Transactional with Spring

Matrilateral answered 27/1, 2020 at 17:7 Comment(0)
D
11

You can also add the following line to your javadoc maven configuration: <failOnError>false</failOnError>. This will tell the javadoc execution to ignore all errors and not let the build fail.

Your complete javadoc plugin config would therefore look like this:

<build>
   <plugins>
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-compiler-plugin</artifactId>
           <configuration>
               <source>1.8</source>
               <target>1.8</target>
           </configuration>
       </plugin>
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-javadoc-plugin</artifactId>
           <configuration>
               <additionalparam>-Xdoclint:none</additionalparam>
               <failOnError>false</failOnError>
           </configuration>
       </plugin>
    </plugins>
</build>
Drysalter answered 7/1, 2015 at 11:15 Comment(1)
This answer does not actually address the problem, it rather hides it. failOnError=true allows Maven to continue the build, but since JavaDoc aborts, not all files are generated. For instance, all index files might not be generated. Can you consider a build with truncated JavaDocs a successful one?Bifid
R
2

InterceptorBinding is available at following maven dependency:

<dependency>
    <groupId>javax.interceptor</groupId>
    <artifactId>javax.interceptor-api</artifactId>
    <version>1.2</version>
</dependency>
Relation answered 22/7, 2018 at 8:45 Comment(0)
I
1

I had the same problem with Spring-Boot 2 Kotlin and gradle. As @kozlovda suggested:

dependencies {
  compileOnly 'javax.interceptor:javax.interceptor-api:1.+'
  ...

fixed the problem

Iridosmine answered 7/9, 2018 at 14:48 Comment(0)
M
0

Replace as below

import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class WorkingService
Melissiamelita answered 5/9, 2019 at 11:51 Comment(0)
O
0

This slightly-more-modern dependency can also be used to resolve the issue:

<dependency>
    <groupId>jakarta.interceptor</groupId>
    <artifactId>jakarta.interceptor-api</artifactId>
    <version>1.2.5</version>
</dependency>
Ovary answered 27/10, 2021 at 20:2 Comment(0)
E
-6

You can also add Maven dependency to your POM file. It solved this problem for me

    <dependency>
        <groupId>net.sourceforge.cobertura</groupId>
        <artifactId>cobertura</artifactId>
        <version>2.1.1</version>
        <scope>compile</scope>
    </dependency>
Enthrall answered 28/12, 2016 at 15:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.