2012-03-21 10 views
1

私はwebstart jnlpファイルを作成するこのantタスクを持っています。複数のjarファイル名を持つant replacetoken

これは、テンプレートファイルから@タイトル@などのようなトークンを置き換える: あるlog4j.jar、xpp.jar、資源:

<?xml version="1.0" encoding="UTF-8"?> 
<jnlp spec="1.0+" codebase="@[email protected]"> 
<information> 
    <title>@[email protected]</title> 
</information> 
<resources> 
    @[email protected] 
</resources> 
<application-desc main-class="@[email protected]"/> 
</jnlp> 

問題は、私は私のlib /ディレクトリには多くの瓶を持っていることです。 jar ... と1 jarsトークン。

@ jars @トークンをjarsファイル名に置き換えるにはどうすればよいですか?あなたが@jarsを交換しようとしている

<target name="webstart" description="Deploy as jnlp webstart"> 
    <copy file="template.jnlp" tofile="test.jnlp"> 
     <filterchain> 
      <replacetokens> 
       <token key="codebase" value="myCodebase" /> 
       <token key="title" value="myTitle" /> 
       <token key="jars" value="jar href="xxx.jar" /> 
      </replacetokens> 
     </filterchain> 
    </copy> 
</target> 
<project/> 

答えて

0

私はアリ-contribのでこれを達成するために管理(プロパティでCDATAでのヒントのためのチャドNouisのおかげで):

<!-- Tricky part is XML content here CDATA Elements are needed, this is the first part--> 
<property name="pre"><![CDATA[ 
    <jar href="]]></property> 

<!-- Tricky part is XML content here CDATA Elements are needed, this is the last part--> 
<property name="after"><![CDATA["/>]]></property> 

<!-- this will be our temp file--> 
<delete file="temp.txt" failonerror="false"/> 

<!-- for task from ant-contrib--> 
<for param="file"> 
    <fileset dir="dist" includes="*.jar"/> 
    <sequential> 
    <!-- write it into a file, using var/properties did not work--> 
    <echo file="temp.txt" append="true">${pre}@{file}${after}</echo> 
    </sequential> 
</for> 

<!-- load file content in property--> 
<loadfile property="xml.data" srcfile="temp.txt"/> 

<!-- finish--> 
    <copy file="template.jnlp" tofile="test.jnlp" overwrite="true"> 
     <filterchain> 
      <replacetokens> 
       <token key="codebase" value="myCodebase" /> 
       <token key="title" value="myTitle" /> 
       <token key="jars" value="${xml.data}" /> 
      </replacetokens> 
     </filterchain> 
    </copy> 

リンク:

0

私が理解から、:

<resources> 
    <jar href="log4J.jar"/> 
    <jar href="xpp.jar"/> 
    <jar href="resources.jar"/> 
</resources> 

これは私のアリプロジェクトの一部である:その出力になることを リテラルXMLを使用した@トークンこれはあなたが後にしているものであるかどうかを確認してください:

<target name="run"> 
    <property name="xml.data"><![CDATA[ 
     <jar href="log4J.jar"/> 
     <jar href="xpp.jar"/> 
     <jar href="resources.jar"/> 
    ]]></property> 

    <copy file="template.jnlp" tofile="test.jnlp"> 
     <filterchain> 
      <replacetokens> 
       <token key="codebase" value="myCodebase" /> 
       <token key="title" value="myTitle" /> 
       <token key="jars" value="${xml.data}" /> 
      </replacetokens> 
     </filterchain> 
    </copy> 
</target> 
+0

、私は彼が解析されるプロパティのコンテンツを必要だと思いますファイルセットに応じて動的に変更します。 – oers

+0

はい、動的に、ここでパスコンバートが見つかりました[リンク](http://stackoverflow.com/questions/1978866/is-it-possible-to-replace-text-in-properties-in-ants-build-xml) と= "$のlib.dir" から= "0​​のhref = "" にreplacestring so: <似の" – Stefan

関連する問題