如何解决 java.lang.NoClassDefFoundError: javax/annotation/Generated?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48238014/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 10:00:38  来源:igfitidea点击:

How can be solved java.lang.NoClassDefFoundError: javax/annotation/Generated?

javahibernatemavenannotations

提问by ziki

I`ve changed jdk to a 9 version in my project and then collided with an error :

我在我的项目中将 jdk 更改为 9 版本,然后与错误发生冲突:

Error:java: java.lang.NoClassDefFoundError: javax/annotation/Generated

I try to solve it by the adding following to pom.com but it wasn`t work for me:

我尝试通过向 pom.com 添加以下内容来解决它,但它对我不起作用:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>${version.compiler.plugin}</version>
   <configuration>
       <!-- fork is needed so compiler args can be used -->
       <fork>true</fork>
       <compilerArgs>
           <arg>-J--add-modules</arg>
           <arg>-Jjava.annotations.common</arg>
       </compilerArgs>
   </configuration>
</plugin>

Does it have other way to solve?

有没有其他办法解决?

回答by Thorbj?rn Ravn Andersen

Add an artifact containing the classes you need to the classpath.

将包含您需要的类的工件添加到类路径。

It appears (untested) that the javax.annotated API is what you need. See https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api/1.3.1for details. You can add the following dependency to your project as any other and it should be present:

看来(未经测试)javax.annotated API 正是您所需要的。有关详细信息,请参阅https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api/1.3.1。您可以像任何其他项目一样将以下依赖项添加到您的项目中,并且它应该存在:

<!-- https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api -->
<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3.1</version>
</dependency>

Remember to remove the compiler arguments!

请记住删除编译器参数!