java compilation error using findbugs. com.sun.tools.javac.code.Symbol$CompletionFailure: class file for javax.annotation.meta.When not found

倖福魔咒の 提交于 2019-12-07 03:01:08

问题


I am trying to use the annotations of findbugs 1.3.2.

I used the edu.umd.cs.findbugs.annotations.NonNull annotation in a simple test, and it works fine.

However, now I have a large project, composed of sub-modules, using maven, and I get the following compilation error by just importing that annotation in some java file:

com.sun.tools.javac.code.Symbol$CompletionFailure: class file for javax.annotation.meta.When not found

what can be the problem? i tried adding the findbugs dependency in all sub-modules. maybe it is a conflict with jsr305? I see that one of our dependencies uses jsr305 1.3.9.


回答1:


In my experience, this error always occurs when you use @NunNull and jsr305.jar is not on the classpath. In order to use the findbugs annotations, you must add both annotations.jar and jsr305.jar to the classpath.
Some annotations (I am thinking of @SuppressWarnings) can be used without jsr305.jar, but @NonNull requires it for sure.

(You mentioned jsr305.jar in your question, but you didn't say explicitly that you've checked. Also, people are going to land here when searching for the error message, and they will need to add jsr305.jar.) Only one version of jsr305.jar should be on the classpath.




回答2:


You can also use this dependency

    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>annotations</artifactId>
        <version>3.0.1</version>
    </dependency>


来源:https://stackoverflow.com/questions/11104667/java-compilation-error-using-findbugs-com-sun-tools-javac-code-symbolcompletio

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!