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 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?
6 Answers
Add an artifact containing the classes you need to the classpath.
It appears that the javax.annotation API is what you need. See for details. You can add the following dependency to your project as any other and it should be present:
<!-- --> <dependency> <groupId>javax.annotation</groupId> <artifactId>javax.annotation-api</artifactId> <version>1.3.2</version> </dependency> Remember to remove the compiler arguments!
6From 2020 onwards, the javax.* modules have been transitioned to jakarta. So the 2020+ proof dependency declaration is now:
<groupId>jakarta.annotation</groupId> <artifactId>jakarta.annotation-api</artifactId> See also a blog with explanations and a complete table with old and new names
implementation 'javax.annotation:javax.annotation-api:1.3.2' annotationProcessor("javax.annotation:javax.annotation-api:1.3.2") 3I had same problem and fixed by adding library javax.annotation-api-1.3.2.jar
I was also facing the same issue. I was working with java8 while in bash_profile the version was java 11. changing that to java 8 worked. Also, i tested in dummy project that the issue(when not version issue) is resolved using javax.annotation-api-1.3.2.
Maybe it's too late, but I also met the same problem like this but other answers are all not working for me, as I'm running an Android project and it already has this in the build.gradle app file.
implementation 'javax.annotation:javax.annotation-api:1.3.2'
After several hours of research, I found the solution, which is add the following line below the above one:
annotationProcessor("javax.annotation:javax.annotation-api:1.3.2")
Hopefully this can help.