Maven - pom 内属性名称中的特殊字符

发布于 2024-12-21 07:02:23 字数 247 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

潜移默化 2024-12-28 07:02:23

$ 是 $ 的转义字符。

只要输入两次,例如

<properties>
  <prop-with-dollar>Prop-with-$</prop-with-dollar>
</properties>

prop-with-dollar 的值将是 Prop-with-$

EDIT

经过更仔细的阅读,意识到问题实际上是关于属性名称中的 $

Maven 中不支持它。这并非没有道理。许多语言仅支持有限的变量名称字符集。例如,在 Java 中 $!<>- 和许多其他字符不能出现在变量名称中。

$ IS an an escape character for $.

Just put it twice, e.g.

<properties>
  <prop-with-dollar>Prop-with-$</prop-with-dollar>
</properties>

the value of prop-with-dollar will be Prop-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.

不交电费瞎发啥光 2024-12-28 07:02:23

我最终所做的是通过在中写入“DOLAR”来使用 maven 替换插件我需要美元符号的每个地方,然后将所有“DOLAR”实例替换为“$”
这是一个代码示例:

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0-alpha-2</version>
        <executions>
          <execution>
            <id>Generating varfile for the install4j</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>write-active-profile-properties</goal>
            </goals>
            <configuration>
              <outputFile>C:\Dev\out.varfile</outputFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>maven-replacer-plugin</artifactId>
        <version>1.4.0</version>
        <executions>
          <execution>
            <id>Replacing the DOLAR sign with real dollar sign in varfile</id>
            <phase>process-resources</phase>
            <goals>
              <goal>replace</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <basedir>C:\Dev\</basedir>
          <file>out.varfile</file>
          <replacements>
            <replacement>
              <token>DOLAR</token>
              <value>\$</value>
            </replacement>
          </replacements>
        </configuration>
      </plugin>

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:

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0-alpha-2</version>
        <executions>
          <execution>
            <id>Generating varfile for the install4j</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>write-active-profile-properties</goal>
            </goals>
            <configuration>
              <outputFile>C:\Dev\out.varfile</outputFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>maven-replacer-plugin</artifactId>
        <version>1.4.0</version>
        <executions>
          <execution>
            <id>Replacing the DOLAR sign with real dollar sign in varfile</id>
            <phase>process-resources</phase>
            <goals>
              <goal>replace</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <basedir>C:\Dev\</basedir>
          <file>out.varfile</file>
          <replacements>
            <replacement>
              <token>DOLAR</token>
              <value>\$</value>
            </replacement>
          </replacements>
        </configuration>
      </plugin>
暖伴 2024-12-28 07:02:23

可以为你工作,值得尝试这个:

<project>
    <properties>
         <a\u0024Boolean>SOMETHING</a\u0024Boolean>
    </properties>
    <!--...-->
</project>

当我想通过解析键 '${log4j.dir}'log4j.properties 文件时,我添加了同样的问题strong> 与 pom 属性值 '${user.home}'

$${key} hack 和 ${dollar}{key} hack 对我来说都不起作用。
我最终设法使用 pom 属性中 $ char 的十六进制表示法来完成此操作。

<project>
    <properties>
    <log4j.dir>\u0024{user.home}</log4j.dir>
    </properties>
    <!--...-->
</project>

祝你好运!

Could work for you, it is worth trying this:

<project>
    <properties>
         <a\u0024Boolean>SOMETHING</a\u0024Boolean>
    </properties>
    <!--...-->
</project>

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.

<project>
    <properties>
    <log4j.dir>\u0024{user.home}</log4j.dir>
    </properties>
    <!--...-->
</project>

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文