为什么 Eclipse 不编译 APT 生成的类?

发布于 2024-09-05 09:49:56 字数 35 浏览 5 评论 0原文

在我的 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒几许 2024-09-12 09:49:56

我不久前就想通了,我想我应该回来解释一下发生了什么。当编译器运行时,它会编译现有的源代码(我编写的源代码),然后从现有的源文件生成源文件,但它不会编译这些生成的类。我最终把它变成了一个 Ant 项目(按照设置 说明)。因此,基本上我有两个任务:第一个任务是生成新的源文件(使用 -proc:only 选项运行 javac 会导致在不编译源代码的情况下进行注释处理),第二个任务是实际编译所有源文件(生成并存在)。

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).

情魔剑神 2024-09-12 09:49:56

您必须刷新 Eclipse 中的“gen”文件夹(例如,从 Package Explorer),以便 Eclipse 能够看到新生成的文件并编译它们。你在做这个吗?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文