0

我想在 ant 属性中放置一个问号字符(通过属性文件),但我不断收到Dangling meta character '?'错误消息。我到底怎么在蚂蚁属性里面放一个问号?


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

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

蚂蚁文件:

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

但是每当我运行 ant 时,我都会得到这个:

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

我到底怎么在蚂蚁属性里面放一个问号?

4

1 回答 1

1

问题似乎出在:

regexp="?"

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

于 2012-12-20T18:10:53.527 回答