如何解决java.lang.NoClassDefFoundError:javax/annotation/Generated? [英] How can be solved java.lang.NoClassDefFoundError: javax/annotation/Generated?

查看:2595
本文介绍了如何解决java.lang.NoClassDefFoundError:javax/annotation/Generated?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

我尝试通过在pom.com上添加以下内容来解决此问题,但这对我来说不起作用:

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

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

推荐答案

将包含所需类的工件添加到类路径.

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

(需要的)似乎是需要的javax.annotated API.参见 https://mvnrepository.com/artifact/javax.annotation/有关详细信息,请参见javax.annotation-api/1.3.1 .您可以将以下依赖项添加到您的项目中,就像其他任何依赖项一样:

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

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

这篇关于如何解决java.lang.NoClassDefFoundError:javax/annotation/Generated?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆