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

查看:53
本文介绍了如何解决 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>

还有其他办法解决吗?

推荐答案

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

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

看来 javax.annotation API 正是您所需要的.请参阅 https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api/1.3.2 了解详情.您可以像任何其他项目一样将以下依赖项添加到您的项目中,并且它应该存在:

It appears that the javax.annotation API is what you need. See https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api/1.3.2 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.2</version>
</dependency>

记得去掉编译器参数!

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

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