Maven - pom 内属性名称中的特殊字符
我正在使用 maven-properties-plugin 将我的属性写入文件,以便第三方应用程序使用。
我想在属性名称中包含特殊字符“$”。
例如:
<properties>
<a$Boolean>SOMETHING</a$Boolean>
...
我找不到转义字符。
我希望有一个解决方案。
谢谢, 伊卡。
I'm using the maven-properties-plugin to write my properties to file in order to be used by a third party application.
I would like to include a special character '$' in the property name.
For example:
<properties>
<a$Boolean>SOMETHING</a$Boolean>
...
I failed to find an escape character.
I would appreciate a solution.
Thanks,
Ika.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
$
是 $ 的转义字符。只要输入两次,例如
prop-with-dollar
的值将是Prop-with-$
EDIT
经过更仔细的阅读,意识到问题实际上是关于属性名称中的
$
。Maven 中不支持它。这并非没有道理。许多语言仅支持有限的变量名称字符集。例如,在 Java 中
$!<>-
和许多其他字符不能出现在变量名称中。$
IS an an escape character for $.Just put it twice, e.g.
the value of
prop-with-dollar
will beProp-with-$
EDIT
After more careful reading, realized that the question is really about
$
in a property name.It is not supported in Maven. Which is not unreasonable. Many languages support only limited set of characters for variable names. For example, in Java
$!<>-
and many other characters cannot appear in a variable name.我最终所做的是通过在中写入“DOLAR”来使用 maven 替换插件我需要美元符号的每个地方,然后将所有“DOLAR”实例替换为“$”
这是一个代码示例:
What I finally did was to use the maven replacer plugin by writing 'DOLAR' in every place I needed the dollar sign and then replacing all instances of 'DOLAR with '$'
Here is a code example:
可以为你工作,值得尝试这个:
当我想通过解析键 '${log4j.dir}'log4j.properties 文件时,我添加了同样的问题strong> 与 pom 属性值 '${user.home}'。
$${key} hack 和 ${dollar}{key} hack 对我来说都不起作用。
我最终设法使用 pom 属性中 $ char 的十六进制表示法来完成此操作。
祝你好运!
Could work for you, it is worth trying this:
I add the same issue when I wanted to filter my log4j.properties file by resolving the key '${log4j.dir}' with the pom property value '${user.home}'.
Neither $${key} hack nor ${dollar}{key} hack worked for me.
I finally managed to do it using the HEXA notation for the $ char in the pom property.
Good luck!