读取 Maven 配置文件属性时出现问题
我在 pom 文件中有一个如下所示的配置文件:
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<application.domain>mydomain.com</application.domain>
<application.name>MyApp</application.name>
</properties>
</profile>
并且我在属性文件中读取了该值,如下所示:
${application.name}
first.key =\u0627\u0644\u062E\u0627\u0635 \u0628\u0643 ${application.name} \u0627\u0633\u062A\u0645\u0631 \u0645\u0639 \u062D\u0633\u0627\u0628
second.key=\u061F ${application.name} \u0644\u064A\u0633 \u0644\u062F\u064A\u0643 \u062D\u0633\u0627\u0628 \u0639\u0644\u0649
它与第一个键一起工作正常,并且该值被成功替换,但对于第二个键和其他类似的键,它不起作用我不知道为什么,有什么想法吗?
i have a profile in the pom file like the following:
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<application.domain>mydomain.com</application.domain>
<application.name>MyApp</application.name>
</properties>
</profile>
and i read this value in the properties file like the following:
${application.name}
first.key =\u0627\u0644\u062E\u0627\u0635 \u0628\u0643 ${application.name} \u0627\u0633\u062A\u0645\u0631 \u0645\u0639 \u062D\u0633\u0627\u0628
second.key=\u061F ${application.name} \u0644\u064A\u0633 \u0644\u062F\u064A\u0643 \u062D\u0633\u0627\u0628 \u0639\u0644\u0649
it works fine with the first key and the value is replaced successfully, but with the second one and other keys like it, it didn't work i don't know why, any ideas ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 pom 文件中添加以下插件后,它对我来说工作得很好:
http://maven.apache.org/plugins/maven-resources-plugin/examples/encoding.html
It worked fine with me after adding the following plugin in the pom file:
http://maven.apache.org/plugins/maven-resources-plugin/examples/encoding.html
如果您想将属性文件中的应用程序名称替换为 Maven pom 中的值,您必须:
您应该为资源过滤定义正确的文件编码(建议使用 UTF-8,但无论如何属性文件必须采用 ascii-7 格式)。
If you want to replace the application name in your properties file with the value in the Maven pom you must:
You should define the proper file encoding for resource filtering (UTF-8 recommended, but anyway the properties files must be in ascii-7 as yours).
也许 Maven 过滤机制因 Unicode 转义而窒息。为什么不直接用 UTF-8 拼写出来呢?
Perhaps the Maven filtering mechanism is choking on the Unicode escapes. Why not just spell it out in UTF-8?