3

I am currently doing this:

<jar update="yes"
     jarfile="${pwd}/dist/${release}_installer.jar">
   <zipfileset src="${pwd}/dist/app.jar" includes="com/izforge/izpack/panels/**"/>
   <zipfileset src="${pwd}/dist/app.jar" includes="com/xyz/img/logo.png"/>
</jar>

My existing installer JAR gets updated to include the files as needed, extracted from the app JAR.

So far, so good.

However, I want to modify the behaviour such that the path of the image file is different than what is being copied from:

Currently:

com/izforge/izpack/panels/MyIzPanel.class
com/xyz/img/logo.png

What I want:

com/izforge/izpack/panels/MyIzPanel.class
blah/img/logo.png

So I need to copy the files, but use <zipfileset> and <jar> in such a way that I can modify the directory structure.

Is there a way to do this, apart from unzipping the entire contents copying file and then zipping it back up again?


EDIT:

Link to earlier related question: ant task to remove files from a jar

Community
  • 1
  • 1
bguiz
  • 27,371
  • 47
  • 154
  • 243

3 Answers3

5

You can use the fullpath attribute:

<zipfileset src="${pwd}/dist/app.jar"
    includes="com/xyz/img/logo.png" fullpath="blah/img/logo.img"/>

If you need to copy several files you may want to have a look at the prefix attribute, e.g.:

<zipfileset src="${pwd}/dist/app.jar"
    includes="**/*.png" prefix="blah/img"/>
Grodriguez
  • 21,501
  • 10
  • 63
  • 107
  • I did trry prefix, h/w I get `blah/img/com/xyz/img/logo.png` instead of `blah/img/logo.png`, which is what I want. – bguiz Oct 01 '10 at 07:51
  • Yup, `fullpath` does work for a single file, however I have got multiple `.png` files which I want to map... I have been looking at the `mapper` ( http://ant.apache.org/manual/Types/mapper.html ) ant types, but haven't managed to get them working... – bguiz Oct 01 '10 at 07:58
  • 1
    For more than one file, if `prefix` does not suit your needs, then yes, you will need to use mappers. – Grodriguez Oct 01 '10 at 08:35
2

In order to modify the directory structure within the archive on the fly you can use the task in combination with <mappedresources>, eg:

<jar file="target.jar" update="true">
  <mappedresources>
    <zipfileset src="source.jar">
      <include name="com/xyz/img/*.png"/>
    </zipfileset>
    <mapper type="glob" from="com/xyz/img/*.png" to="bla/img/*.png" />
  </mappedresources>
</jar>
Hachmaninow
  • 572
  • 5
  • 6
0

You should probably look into zipgroupfileset as explained here.

Community
  • 1
  • 1
Jarek Przygódzki
  • 4,284
  • 2
  • 31
  • 41