gpt4 book ai didi

Java 6 : how to pass multiple parameters to APT

转载 作者:行者123 更新时间:2023-11-29 09:24:35 26 4
gpt4 key购买 nike

我有一个从 AbstractProcessor 扩展的 Java 注释处理器.

我有两个支持的选项,addResDirverbose ,我正在尝试这样设置它们:

-AaddResDir=src/main/webapp -Averbose=true

我也试过这个:

-AaddResDir=src/main/webapp,verbose=true

虽然单个参数有效,例如

-AaddResDir=src/main/webapp

我无法使用多个参数,也找不到任何相关文档。 APT中需要手动解析参数吗?

我唯一拥有的是 javac -help 的输出:

-Akey[=value]   Options to pass to annotation processors

编辑

毕竟这是一个maven问题。这是我的 Maven 配置:

<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<optimize>true</optimize>
<debug>true</debug>
<compilerArgument>-AaddResDir=src/main/webapp -Averbose=true</compilerArgument>
</configuration>
</plugin>

不幸的是,maven 将参数作为 args 数组中的单个字符串发送给 Javac,而它当然应该是两个字符串。 map 版<compilerAguments>也没有帮助,因为

<Averbose>true</Averbose>
<AaddResDir>src/main/webapp</AResDir>

生成输出:

[... , -Averbose, true, -AaddResDir, src/main/webapp]

虽然javac需要语法

[... , -Averbose=true, -AaddResDir=src/main/webapp ]

<Averbose=true />
<AaddResDir=src/main/webapp />

是无效的 XML。

(参见 Mapping Maps 来自 Guide to Configuring Maven Plugins )

而且我恐怕没有办法改变这一点,啊。


编辑:

我现在有 filed a bug report .

最佳答案

目前还没有真正的答案。

提交错误:MCOMPILER-135

我已经提交了三个不同的补丁,the last of which引入类型为 Properties 的变量:

<additionalCompilerArguments>
<property> <name>-Akey=value</name> </property>
<property> <name>-verbose</name> </property>
<property> <name>-Xmaxerrs</name> <value>1000</value> </property>
</additionalCompilerArguments>

此解决方案是最灵活的解决方案,因为它支持许多不同的参数语法格式。

(如果现有参数 <compilerArguments> 也是 Properties 类型,我的问题就会解决)

关于Java 6 : how to pass multiple parameters to APT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3700357/

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