如何在源代码中以编程方式定义 myAnnotationProcessor?

发布于 2024-11-25 03:02:50 字数 167 浏览 1 评论 0原文

我刚刚接触注释。 我创建了一个示例annotationProcessor来处理我的注释,并且当前使用命令行脚本“-processor defaultproject.annotations.DefaultProcessor”来使用它。

有什么方法可以从代码内部设置这个处理器吗?

多谢 莫因

I'm just new to annotations.
I've created a sample annotationProcessor to handle my annotations and currently using command line script "-processor defaultproject.annotations.DefaultProcessor " to use it.

is there any way to set this processor from inside the code?

thanks a lot
Moein

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

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

发布评论

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

评论(1

星星的軌跡 2024-12-02 03:02:50

处理器接口说的是发现过程:

该工具使用发现过程来查找注释处理器并
决定是否应该运行它们。通过配置该工具,
可以控制一组潜在的处理器。例如,对于一个
JavaCompiler 要运行的候选处理器列表为 设置
直接
或由搜索路径控制 用于
服务式查找。其他工具实现可能有
不同的配置机制,例如命令行选项;为了
详细信息,请参阅特定工具的文档。

在类路径中定义处理器的最佳选择是提供包含文本 defaultproject.annotations.DefaultProcessorMETA-INF/services/javax.annotation.processing.Processor 文件。

(假设您的工具链支持此机制。这最终取决于编译器/工具/IDE。)

The Processor interface says this about the discovery process:

The tool uses a discovery process to find annotation processors and
decide whether or not they should be run. By configuring the tool, the
set of potential processors can be controlled. For example, for a
JavaCompiler the list of candidate processors to run can be set
directly
or controlled by a search path used for a
service-style lookup. Other tool implementations may have
different configuration mechanisms, such as command line options; for
details, refer to the particular tool's documentation.

Your best bet for defining the processor in your classpath is to provide a META-INF/services/javax.annotation.processing.Processor file containing the text defaultproject.annotations.DefaultProcessor.

(Assuming your tool chain supports this mechanism. This is ultimately compiler/tool/IDE dependent.)

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