Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用ant脚本替换所有匹配项_Ant - Fatal编程技术网

如何用ant脚本替换所有匹配项

如何用ant脚本替换所有匹配项,ant,Ant,如何替换所有匹配的行?我想替换*xml文件中的所有匹配行。 下面的脚本片段仅替换一行 提前谢谢。 brgds ${hibernate.jndi.url.live} ${providerurl.live} 与其尝试就地编辑文件,不如将复制任务用作模板系统,它支持一个可用于替换生产值的模板系统 例子 编译文件 persistence.xml java:/DefaultDS 这段代码对我很有用: <?xml version="1.0" encoding="windows-1252" ?&

如何替换所有匹配的行?我想替换*xml文件中的所有匹配行。 下面的脚本片段仅替换一行 提前谢谢。 brgds


${hibernate.jndi.url.live}
${providerurl.live}

与其尝试就地编辑文件,不如将复制任务用作模板系统,它支持一个可用于替换生产值的模板系统

例子 编译文件

persistence.xml

java:/DefaultDS

这段代码对我很有用:

<?xml version="1.0" encoding="windows-1252" ?>
<project default="init" basedir=".">
  <property file="build.properties"/>
  <target name="init">
    <tstamp/>
    <loadfile property="jndiurl"
              srcfile="${src.model}/META-INF/persistence.xml">
      <filterchain>
        <linecontains>
          <contains value="hibernate.jndi.url"></contains>
        </linecontains>
        <headfilter lines="1"/>
      </filterchain>
    </loadfile>
    <echo>${jndiurl}</echo>
    <replace file="${src.model}/META-INF/persistence.xml" token="${jndiurl}"
             value="${hibernate.jndi.url.live}${line.separator}"/>
    <echo>${hibernate.jndi.url.live}</echo>
</project>

${jndirol}
${hibernate.jndi.url.live}

谢谢你,马克·奥康纳。您在回答中建议的方法完全正确,但不幸的是,我们没有build.xml文件。因为我们在JDeveloperADF平台中使用ojdeploy,还有一些愚蠢的原因,所以我们不使用ant构建流程。
.
├── build.xml
└── src
    └── resources
        └── persistence.xml
<project name="demo" default="template">

    <target name="template">
        <copy todir="build/META-INF">
            <fileset dir="src/resources" includes="*.xml"/>
            <filterset>
                <filter token="HIBERNATE.HBM2DDL.AUTO" value="create-drop"/>
            </filterset>
        </copy>
    </target>

    <target name="clean">
        <delete dir="build"/>
    </target>

</project>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
   <persistence-unit name="sample">
      <jta-data-source>java:/DefaultDS</jta-data-source>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="@HIBERNATE.HBM2DDL.AUTO@"/>
      </properties>
   </persistence-unit>
</persistence>
<?xml version="1.0" encoding="windows-1252" ?>
<project default="init" basedir=".">
  <property file="build.properties"/>
  <target name="init">
    <tstamp/>
    <loadfile property="jndiurl"
              srcfile="${src.model}/META-INF/persistence.xml">
      <filterchain>
        <linecontains>
          <contains value="hibernate.jndi.url"></contains>
        </linecontains>
        <headfilter lines="1"/>
      </filterchain>
    </loadfile>
    <echo>${jndiurl}</echo>
    <replace file="${src.model}/META-INF/persistence.xml" token="${jndiurl}"
             value="${hibernate.jndi.url.live}${line.separator}"/>
    <echo>${hibernate.jndi.url.live}</echo>
</project>