Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant using Fileset in jar task and renaming files

Tags:

jar

ant

I have the following piece of code:

<jar destfile="${jar.file}">
     <fileset dir="${basedir}/resources"/>
        <include name="META-INF/ejb-jar.xml"/>
        <include name="META-INF/persistence-prod.xml"/>
     </fileset>
     [...]
</jar>

The problem is that persistence-prod.xm1 should be persistence.xml when placed in the jar.

I know I could create a working directory and layout my whole jar there, and then jar that up. I know I can copy that one file elsewhere and rename it while copying. If I had a whole bunch of files named *-prod.xml to be renamed *.xml, I can use a file mapper inside the copy task. However, I want to be able to rename the file right in the <jar> task. I tried adding <globmapper> to the jar task, but I got the error message: jar doesn't support the nested "globmapper" element.

Any idea how this rename can take place while jaring the file?

like image 413
David W. Avatar asked Jun 24 '13 14:06

David W.


1 Answers

Of course, the minute I asked the question, I figure out the answer:

I can't put <globmapper> directly into a <jar> task, but I can include <mappedresources> into the <jar> task, and place my <globmapper> in there:

Wrong:

<jar destfile="${jar.file}">
     <fileset dir="${basedir}/resources"/>
          <include name="META-INF/ejb-jar.xml"/>
          <include name="META-INF/persistence-prod.xml"/>
     </fileset>
     <globmapper from="*-prod.xml" to="*.xml"/>
     [...]
</jar>

Right:

<jar destfile="${jar.file}">
    <fileset dir="${basedir}/resources"/>
         <include name="META-INF/ejb-jar.xml"/>
    </fileset>
    <mappedresources>
        <fileset dir="${basedir}/resources">
            <include name="META-INF/persistence-prod.xml"/>
        </fileset>
        <globmapper from="*-prod.xml" to="*.xml"/>
    </mappedresources>
    [...]
</jar>

I guess this makes sense since it limits my file mapping to just the <mappedresources> and not to all <fileset> of the <jar> task.

like image 145
David W. Avatar answered Oct 13 '22 19:10

David W.