Maven-资源过滤:资源文件中@符号的含义 [英] Maven - resource filtering : implications of the @ symbol in resource files

查看:215
本文介绍了Maven-资源过滤:资源文件中@符号的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Maven程序集插件为不同的环境准备一些配置工件,并且正在使用资源过滤来替换参数值.

I am using the Maven assembly plugin to prepare some configuration artifacts for different environments, and I am using resource filtering to substitute parameter values.

我遇到了一个奇怪的行为,我有一个属性文件,其内容如下:

I came across a weird behaviour where I had a property file with the contents as follows:

###########################

###########################

#author.name@company.com#

# author.name@company.com #

############################

############################

env.name = $ {replacement.value}

env.name=${replacement.value}

作者的电子邮件中出现"@"符号导致所有属性引用都被忽略.

The presence of the '@' symbol for the author's e-mail was causing all property references to be ignored.

我试图寻找有关发生这种情况的文档-但找不到任何能解决此问题的方法.任何有益于记录或解释的指针将不胜感激.

I have tried looking for documentation as to why this happens - but cannot find anything that answers this behaviour. Any helpful pointers to documention or an explanation would be much appreciated.

供参考:

  1. Maven版本:2.2.1
  2. Maven程序集插件版本:2.2

推荐答案

我试图寻找有关发生这种情况的文档-但找不到任何能解决此问题的方法.任何对文档或解释的有用指示将不胜感激.

I have tried looking for documentation as to why this happens - but cannot find anything that answers this behaviour. Any helpful pointers to documentation or an explanation would be much appreciated.

This is not documented in the filtering section of the Maven Assembly Plugin but it looks like it uses the same default delimiters as the Maven Resources Plugin which are:

<build>
  ...
  <plugin>
    ...
    <configuration>
      ...
      <delimiters>
        <delimiter>${*}</delimiter>
        <delimiter>@</delimiter>
      </delimiters>

因此,以下内容也会被过滤:

So the following would be filtered as well:

env.name=@replacement.value@

这也解释了为什么电子邮件地址中的单个@会引起麻烦(插件从未找到结尾定界符).

And this also explains why a single @ in the email address is causing troubles (the plugin never finds the end delimiter).

可以配置分隔符和转义字符串,就像使用针对单个目标的Maven组件插件文档提供了详细信息.

It is possible to configure the delimiters and an escape string, just as it is when using the Maven Resources Plugin. The Maven Assembly Plugin documentation for the single goal provides the details.

对于这种特殊的电子邮件地址情况,一种廉价的解决方法是避免在文件中使用单个@进行过滤:

A cheap workaround, for this particular email address situation, would be to avoid using a single @ in the file to filter:

##############################
# author.name aT company.com #
##############################

env.name=${replacement.value}

作为一项好处,您将避免垃圾邮件:)

And as a benefit, you'll avoid spam :)

这篇关于Maven-资源过滤:资源文件中@符号的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆