java.util.regex.PatternSyntaxException:使用ant在索引0附近非法重复

时间:2017-01-30 11:32:21

标签: java xml ant

我刚刚开始使用Ant。我想将一些数据附加到context-value标记。

这是XML

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/abc.xml</param-value>
    </context-param>
</web-app>

这是ant build target

<target name="deploy">
    <!-- edit web.xml to update context-param-->
    <replaceregexp file="$web.xml" match='${web-app.context-param.param-value}' replace="${web-app.context-param.param-value},/WEB-INF/new.xml" />
</target>

但是显示

java.util.regex.PatternSyntaxException: Illegal repetition near index 0
${web-app.context-param.param-value}
^
        at java.util.regex.Pattern.error(Pattern.java:1924)
        at java.util.regex.Pattern.closure(Pattern.java:3104)
        at java.util.regex.Pattern.sequence(Pattern.java:2101)
        at java.util.regex.Pattern.expr(Pattern.java:1964)
        at java.util.regex.Pattern.compile(Pattern.java:1665)
        at java.util.regex.Pattern.<init>(Pattern.java:1337)
        at java.util.regex.Pattern.compile(Pattern.java:1047)
        at org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher.getCompiledPattern(Jdk14RegexpMatcher.java:68)
        at org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher.matches(Jdk14RegexpMatcher.java:95)
        at org.apache.tools.ant.taskdefs.optional.ReplaceRegExp.doReplace(ReplaceRegExp.java:336)
        at org.apache.tools.ant.taskdefs.optional.ReplaceRegExp.replaceAndWrite(ReplaceRegExp.java:527)
        at org.apache.tools.ant.taskdefs.optional.ReplaceRegExp.multilineReplace(ReplaceRegExp.java:522)
        at org.apache.tools.ant.taskdefs.optional.ReplaceRegExp.doReplace(ReplaceRegExp.java:427)
        at org.apache.tools.ant.taskdefs.optional.ReplaceRegExp.execute(ReplaceRegExp.java:487)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        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:435)
        at org.apache.tools.ant.Target.performTasks(Target.java:456)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
        at org.apache.tools.ant.Main.runBuild(Main.java:854)
        at org.apache.tools.ant.Main.startAnt(Main.java:236)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

我怎样才能使这个工作,问题是什么?

1 个答案:

答案 0 :(得分:0)

实际上,我错过了为文件web.xml包含xmlproperty。

<xmlproperty file="web.xml" collapseAttributes="true" />

将上面的行添加到我的build.xml后,这可以正常工作。