蚂蚁财产内的问号

时间:2012-12-20 17:34:44

标签: ant

我想在ant属性中添加一个问号字符(通过属性文件),但我一直收到Dangling meta character '?'错误。我怎么在蚂蚁属性中加上一个问号?


我在ant属性文件中有以下内容:

 installerTemplate=E:/projectX/branch/?/path/to/installer.exe
 installerBranch=foobar

ant文件:

<project .... >
    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
    <property file="project.properties" />

    <target name="fixPath">
        <propertyregex property="installerFileLocation" input="${installerTemplate}"
            regexp="?" replace="${installerVersion}" global="true" />
        <propertyregex property="installerFileLocation.win" input="${installerFileLocation}"
            regexp="/" replace="\\\\"/>
        <echo>${installerFileLocation.win}</echo>
    </target>
</project>

但每当我运行蚂蚁时,我都会这样:

BUILD FAILED
E:\p4-abird\depot_cfg\ssb\tools\ssb_dev_env_automation\create_ssb_vm.xml:37: java.util.regex.PatternSyntaxException: Dangling meta character '?' near index 0
?
^
    at java.util.regex.Pattern.error(Pattern.java:1713)
    at java.util.regex.Pattern.sequence(Pattern.java:1878)
    at java.util.regex.Pattern.expr(Pattern.java:1752)
    at java.util.regex.Pattern.compile(Pattern.java:1460)
    at java.util.regex.Pattern.<init>(Pattern.java:1133)
    at java.util.regex.Pattern.compile(Pattern.java:847)
    at org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher.getCompiledPattern(Jdk14RegexpMatcher.java:67)
    at org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher.matches(Jdk14RegexpMatcher.java:94)
    at net.sf.antcontrib.property.RegexTask.doReplace(RegexTask.java:135)
    at net.sf.antcontrib.property.RegexTask.execute(RegexTask.java:192)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:392)
    at org.apache.tools.ant.Target.performTasks(Target.java:413)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:811)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 0 seconds

我如何在ant属性中添加问号?

1 个答案:

答案 0 :(得分:1)

问题似乎在于:

regexp="?"

'?'是正则表达式元字符,在正则表达式模式中具有特殊含义。如果你想匹配文字“?” char,你需要逃避它。