JDK8-在尝试使用 Maven javadoc 插件生成 javadoc 时错误“ class file for javax.ceptor.InterceptorBinding not found”

我正在使用 JDK8(在我的 Eclipse 工作区中使用由 Jenkins-JDK-8u20-Linux-x64启动的 Linux 上的 Win x64 u25 JDK + 进行了尝试,两者的问题相同)。

我有一个多模块的 Maven 项目(我从一个主模块启动 Maven 目标“ javadoc: total”,包装类型为“ pom”)。

造型部分看起来像这样:

<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>

我总是收到错误:

[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

我尝试了所有可能的方法,并尝试在谷歌上搜索了很长时间,但没有成功。 我发现了一些链接,其中人们有类似的问题,但没有任何关于可能的解决方案的信息:

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

Http://mail-archives.apache.org/mod_mbox/maven-users/201409.mbox/%3c54101e24.6060304@gmx.de%3e (建议将 JDK8更新为 > update 20,我这样做了,但问题仍然没有改变)。

任何提示或任何人也经历过这种行为(不幸的是,由于某种原因,它看起来相当“罕见”的问题) ? 非常绝望。

47666 次浏览

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>

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

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.

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>

@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.

InterceptorBinding is available at following maven dependency:

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

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

Replace as below

import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class WorkingService

Use

import org.springframework.transaction.annotation.Transactional;

instead of

import javax.transaction.Transactional;

when you are using @Transactional with Spring

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>