JDK8 - 尝试使用 Maven javadoc 插件生成 javadoc 时出现错误“找不到 javax.interceptor.InterceptorBinding 的类文件”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27808734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JDK8 - Error "class file for javax.interceptor.InterceptorBinding not found" when trying to generate javadoc using Maven javadoc plugin
提问by Michal Aron
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).
我正在使用 JDK8(在我的 Eclipse 工作区中使用 Win x64 u25 JDK + 在 Jenkins 启动的 Linux 上进行了尝试 - jdk-8u20-linux-x64,两者都有相同的问题)。
I have multi-module Maven project (I am launching Maven goal "javadoc:aggregate" from a main module with packaging type "pom").
我有一个多模块 Maven 项目(我正在从一个包装类型为“pom”的主模块中启动 Maven 目标“javadoc:aggregate”)。
Pom build section looks like this:
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>
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:
我已经尝试了所有可能的方法,并尝试在 Google 上搜索了很长时间,但没有成功。我找到了人们遇到类似问题的链接,但没有关于可能的解决方案的任何信息:
http://marc.info/?l=maven-user&m=139615350913286&w=2
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).
http://mail-archives.apache.org/mod_mbox/maven-users/201409.mbox/%[email protected]%3E(建议将JDK8更新到>更新20,我做了,但问题仍然存在相同)。
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...
任何提示或任何人也经历过这种行为(不幸的是,由于某种原因,它看起来非常“罕见”的问题)?对这个很绝望...
采纳答案by kozlovda
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:
这似乎是由于javax.transaction.Transactional
(或您的类路径中的任何其他类)本身被注释为javax.interceptor.InterceptorBinding
,除非在依赖项中明确声明,否则在类路径中缺少它:
@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.+(ororg.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 ofTransactional
, is not required for normal operation and (looks like because of this) is not getting fetched as a transitive dependency of your JPA framework.
javax.transaction.Transactional
- 附带javax.transaction:javax.transaction-api:1.+(或org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.0.Final
),通常用于 JPA/ORM/JMS 应用程序以注释事务方法。javax.interceptor.InterceptorBinding
- 应该带有javax.interceptor:javax.interceptor-api:1.+。但是,虽然在 之上声明,但Transactional
不是正常操作所必需的,并且(因此看起来)不会作为 JPA 框架的传递依赖项获取。
As a result JDK8 javadoc tool fails to process the sources (if any of them are annotated with @Transactional
).
因此,JDK8 javadoc 工具无法处理源代码(如果其中任何一个带有 注释@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.
问题修复:添加javax.interceptor:javax.interceptor-api:1.+
依赖项修复了问题。
<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
注意(2020 年 1 月):最新(合理的)版本目前是 1.2.2(参见https://mvnrepository.com/artifact/javax.interceptor/javax.interceptor-api
回答by dfme
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.
您也可以将下面的行添加到您的javadoc Maven配置:<failOnError>false</failOnError>
。这将告诉 javadoc 执行忽略所有错误并且不会让构建失败。
Your complete javadoc plugin config would therefore look like this:
因此,您完整的 javadoc 插件配置将如下所示:
<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>
回答by Andreas Siegel
As @kozlovda already mentions, the issue comes with the @Transactional
annotation (javax.transaction.Transactional
).
正如@kozlovda 已经提到的,问题来自@Transactional
注释 ( 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
.
如果您在为 Spring 应用程序运行 Maven 时遇到所描述的错误,还有另一种解决问题的方法:确保不要使用来自 的注释javax.transaction
,而是使用org.springframework.transaction.annotation.Transactional
.
Replacing the import fixed the issue for me.
替换导入为我解决了这个问题。
回答by Ev.Rei.
You can also add Maven dependency to your POM file. It solved this problem for me
您还可以将 Maven 依赖项添加到 POM 文件中。它为我解决了这个问题
<dependency>
<groupId>net.sourceforge.cobertura</groupId>
<artifactId>cobertura</artifactId>
<version>2.1.1</version>
<scope>compile</scope>
</dependency>
回答by chrisinmtown
@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:
@lpratlong 在评论中提供的答案中说“将其添加为 maven-javadoc-plugin 的附加依赖项”。这对我有用,这是完整的 Maven 插件条目,供像我这样不耐烦的人复制粘贴:
<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.
版本被注释掉是因为在我的情况下 spring-boot 管理版本,只需根据需要恢复。
回答by Oleksii Kyslytsyn
InterceptorBinding is available at following maven dependency:
InterceptorBinding 可在以下 maven 依赖项中使用:
<dependency>
<groupId>javax.interceptor</groupId>
<artifactId>javax.interceptor-api</artifactId>
<version>1.2</version>
</dependency>
回答by Oliver Sahner
I had the same problem with Spring-Boot 2 Kotlin and gradle. As @kozlovda suggested:
我在 Spring-Boot 2 Kotlin 和 gradle 上遇到了同样的问题。正如@kozlovda 建议的那样:
dependencies {
compileOnly 'javax.interceptor:javax.interceptor-api:1.+'
...
fixed the problem
解决了问题
回答by Fred Ondieki
Replace as below
替换如下
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class WorkingService
回答by gfkl
Use
用
import org.springframework.transaction.annotation.Transactional;
instead of
代替
import javax.transaction.Transactional;
when you are using @Transactional with Spring
当你在 Spring 中使用 @Transactional 时