简体   繁体   中英

Why aren't APT generated classes being compiled by Eclipse?

In my Eclipse project I'm using a third-party annotation processor, Hibernate Metamodel Generator to be exact. The annotation processor works as expected and generates .java files as specified by the spec. These files are generated into the directory of the Eclipse project under a "gen" folder. In the project properties this is correctly reflected since two source folders exist - "src" and "gen." However, when the project is built for some reason all the [generated] sources under "gen" are not compiled (checking the "bin" directory I only see .class files from the "src" directory). Does anyone know why this is happening?

I figured it out a while ago and thought I'd come back and explain what happens. When the compiler is run it compiles the existing sources (the ones that I wrote) and then generates source files from the existing source files but it doesn't compile these generated classes. I ended up turning this into an Ant project (as per setup instructions ). So, basically I had two tasks: first to generate new source files (running javac with the -proc:only option causes annotation processing to happen without compiling the sources) and the second to actually compile all sources (generated and existing).

You will have to refresh the "gen" folder in Eclipse (eg from the Package Explorer) in order for Eclipse to see the newly generated files and compile them. Are you doing this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM