IntelliJ IDEA 中的注解处理器编译 [英] Annotation Processor compilation in IntelliJ IDEA
问题描述
我使用的是最新版本的 IntelliJ IDEA (13.1.4) 并且我正在开发我自己的自定义注释.
I'm using the latest version of IntelliJ IDEA (13.1.4) and I'm developing my own custom annotation.
我的项目目前有两个模块
I currently have two modules on my project
- MyOwnCustomAnnotationProcessor(这里我有实际的处理器)
- MyOwnCustomAnnotationProcessorTest(我基本上对几个类进行了注释,以查看它们是否都能正常生成)
我在 Eclipse 中工作,但我正在尝试迁移 ot IntelliJ,因为我无法忍受 Eclipse.通过让 Ant 构建生成主项目的 .jar 文件,并且测试类将使用此 .jar,我设法在 Eclipse 中实现了一些工作.
I was working in Eclipse but I'm trying to migrate ot IntelliJ because I can't stand Eclipse. I managed to make it kinda-of work in Eclipse by having an Ant build generating the .jar file of the main project and the Test classes would use this .jar.
但我不能让它在 IntelliJ 上运行.
But I can't make it work on IntelliJ.
在<代码>设置->编译器 ->Annotation Processor 我有一个新的配置文件,测试项目在这个配置文件里面,配置文件是这样的:
In Settings -> Compiler -> Annotation Processor
I have a new profile, the test project is inside this profile, the profile is like:
我还尝试将 Processor Path
更改为输出文件夹(其中有类 n META-INF),但没有成功.generated
文件夹正在由 IDE 创建,但没有找到任何处理器.
I've also tried changing the Processor Path
to the output folder (where there're classes n META-INF) but no luck. The generated
folder is being created by the IDE, but it's not finding any processors.
关于如何在此处进行的任何提示?
Any tip on how to proceed here?
推荐答案
我最终找到了如何去做,如果有人感兴趣:
I ended up finding how to do it, if anyone is interested:
- 在
Project Structure
菜单中,向主项目(注解处理器项目)添加一个artifact
.此工件导出带有注释处理器的.jar
文件.确保启用Build on Make
,这样每次请求Rebuild Project
时都会生成一个新的.jar - 在
设置 - >编译器 ->Annotation Processor
开启注解处理,勾选Processor Path
并放置导出的.jar
文件的路径.确保放置处理器.
- In
Project Structure
menu add anartifact
to the main project (the annotation processor project). This artifact exports a.jar
file with the annotation processor. Make sure to enableBuild on Make
, that way a new .jar will be generated every time you ask toRebuild Project
- In
Settings - > Compiler -> Annotation Processor
Enable annotation processing, checkProcessor Path
and put the path of the exported.jar
file. Make sure to put the processor.
这应该就是全部了.现在,每次点击 rebuilt project
时都会生成一个新的 jar,第二个项目将使用该新 jar 重新生成.
and that should be all.
Now everytime rebuilt project
is clicked a new jar is generated and the second project will be re-generated with that new jar.
这篇关于IntelliJ IDEA 中的注解处理器编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!