0

一致するすべての行を置き換えるにはどうすればよいですか? *xml ファイル内の一致するすべての行を置き換えたい。以下のスクリプト スニペットは、1 行だけを置き換えます。よろしくお願いします。brgds

<?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>
      </filterchain>
    </loadfile>
    <replace file="${src.model}/META-INF/persistence.xml" token="${jndiurl}"
             value="${hibernate.jndi.url.live}${line.separator}"/>
    <echo>${hibernate.jndi.url.live}</echo>
    <loadfile property="providerurl"
              srcfile="${src.structure}/com/arsivist/structure/connection.properties">
      <filterchain>
        <linecontains>
          <contains value="providerurl"></contains>
        </linecontains>
      </filterchain>
    </loadfile>
    <replace file="${src.structure}/com/arsivist/structure/connection.properties"
             token="${providerurl}"
             value="${providerurl.live}${line.separator}"/>
    <echo>${providerurl.live}</echo>
    <loadfile property="ucmusername"
              srcfile="${src.roketsanutil}/com/arsivist/util/ucmConnection.properties">
      <filterchain>
        <linecontains>
          <contains value="username"></contains>
        </linecontains>
      </filterchain>
  </target>
</project>
4

2 に答える 2

1

ファイルをその場で編集しようとする代わりに、コピー タスクをテンプレート システムとして使用する方が簡単ではないでしょうか。これは、運用値を置き換えるために使用できるフィルターセットをサポートしています。

.
├── build.xml
└── src
    └── resources
        └── persistence.xml

build.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.xml

<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>
于 2013-01-31T21:08:33.980 に答える
0

そのスニペットは私のために働きます:

<?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>
于 2013-02-01T10:57:11.453 に答える