开发者

Issue with reading maven profile property

开发者 https://www.devze.com 2023-03-05 04:13 出处:网络
i have a profile in the pom file like the following: <profile> <id>local</id> <activation>

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 ${applicatio开发者_如何学Gon.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 ?


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


If you want to replace the application name in your properties file with the value in the Maven pom you must:

  1. Use @variable@ format in you properties file! It's a Maven variable I understand.
  2. activate resource filtering for resources (at least for your properties file)

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).


Perhaps the Maven filtering mechanism is choking on the Unicode escapes. Why not just spell it out in UTF-8?

first.key =الخاص بك ${application.name} استمر مع حساب
second.key=؟ ${application.name} ليس لديك حساب على
0

精彩评论

暂无评论...
验证码 换一张
取 消