Class file not found in IntelliJ

前端 未结 8 1363
孤独总比滥情好
孤独总比滥情好 2020-12-15 17:59

In IntelliJ I get this weird error when I try to compile.

Cannot find annotation method \'cascade()\' in type \'javax.persistence.ManyToOne\': class file for         


        
相关标签:
8条回答
  • 2020-12-15 18:23

    Just got this myself but non of those things were my issue. I downloaded a project from github, then opened in intelli J with the problem after trying to run a junit test.

    Solution: Project Structure -> Modules -> 'Project_Name' -> Sources (tab) -> click src folder -> Mark as: Sources

    This should highlight src to be blue and all the class files should be the circles with C instead of looking like normal files. Try running a test again and see if that does it.

    0 讨论(0)
  • 2020-12-15 18:28

    In intelliJ I got this problem when I built (ctrl+shift+F9) at the file level.

    The reason is, I had changes in other files in the same maven project, that were not getting picked.

    I solved it by building at the project level (Select the Maven project in intellij and press ctrl+shift+F9)

    0 讨论(0)
  • 2020-12-15 18:33

    I'm sure, it is too late to answer, but I had to follow a different approach for this error to resolve this issue.

    I had to create this as global library and add that library to the module, then only the error is resolved.

    Add this as a global library

    Then add that library as dependency to the project

    0 讨论(0)
  • 2020-12-15 18:34

    Try to tick a checkbox "export" in your dependencies.

    I mean: "File" menu -> Project Structure -> Modules -> Dependencies, and there you can see libs included to the module. You should also see a checkbox near each lib in column 'Export'.

    0 讨论(0)
  • 2020-12-15 18:34

    Here's an idea: Maybe you have multiple versions of your jar file. Search your folder hierarchy for the file ejb3-persistence.jar, using a file management tool such as Total Commander. Multiple appearances of the file in your classpath may confuse IntelliJ Idea into not recognizing the proper class in the proper jar.

    0 讨论(0)
  • 2020-12-15 18:39

    I was getting the class not found error message when trying to execute a .groovy test class, which referenced a .groovy file (located in the root of the source directory of a submodule - i.e. no packages).

    Moving the source file .groovy into a package, fixed the issue for me.

    Move:

    src/main/groovy/RunMe.groovy
    

    to

    src/main/groovy/somePackage/RunMe.groovy
    
    0 讨论(0)
提交回复
热议问题