使用 Ant 的 Java 6 注释处理配置 [英] Java 6 annotation processing configuration with Ant

查看:32
本文介绍了使用 Ant 的 Java 6 注释处理配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义注释,它是处理器 &处理器工厂.我如何配置我的 Ant 构建文件,以便:

I have a custom annotation and it's processor & processorFactory. How do I configure my Ant build file such that:

  1. 注解处理器应用于注解类并在gen"文件夹中生成源文件

  1. The annotation processor is applied on annotated classes and generates source files inside "gen" folder

生成的源文件(来自注解处理)可以被项目中的其他源文件使用.

The generated source files(from annotation processing) could be used by other source files in project.

推荐答案

这并不漂亮,但这就是我所做的.(来源 javac ant task javac man page) 使用 compilerarg 属性我可以传入注解处理相关的非直接参数由 javac ant 任务支持.

This is not pretty, but it is what I do. (Sources javac ant task javac man page) Using the compilerarg attribute I can pass in the annotation processing related arguments that are not directly supported by the javac ant task.

<javac srcdir="${src}" destdir="${classes}" ... > 
     ....
     <compilerarg line="-processorpath ${processorpath}"/>
     <compilerarg line="-processor ${processor}"/>
     <compilerarg line="-s ${whereToPutGeneratedClassFiles}"/>
</javac>

我不使用 APT 工具,因为文档说明

I do not use the APT tool because the documentation states

请注意,Apt 工具似乎是 JDK 框架的不稳定部分,因此在未来版本中可能会发生根本性的变化.特别是它在 JDK 6 中可能已经过时,它可以作为 javac 的一部分运行注释处理器.

Be advised that the Apt tool does appear to be an unstable part of the JDK framework, so may change radically in future versions. In particular it is likely to be obsolete in JDK 6, which can run annotation processors as part of javac.

如果你真的不关心编译器参数,你可以像这样 jar 你的注解处理器

If you really don't care for compiler args, you can jar your annotation processors like this

<jar destfile="${annotationprocessorjar}" ... >
     ...
     <service type="javax.annotation.processing.Processor" provider="${your.annotation.processor.fully.qualified.name}"/>
</jar>

然后你就可以了

 <javac ... make sure ${annotationprocessorjar} is in classpath>
 </javac>

这篇关于使用 Ant 的 Java 6 注释处理配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆