gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:16:18 25 4
gpt4 key购买 nike

我只是注释的新手。我创建了一个示例 annotationProcessor 来处理我的注释,目前使用命令行脚本“-processor defaultproject.annotations.DefaultProcessor”来使用它。

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

非常感谢萌因

最佳答案

Processor interface说到发现过程:

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.

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

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

关于java - 如何在源代码中以编程方式定义 myAnnotationProcessor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6716110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com