Search code examples
antfilepathunzipunjar

How to use ant unjar file from a jar into a specific directory without path from jar


I want to copy files from within a jar to a specific directory without preserving the path in the jar.

I can use unjar to find just the files I want from the jar OK:

<unjar dest="some_dest_path" overwrite="true" src="somejar.jar">
    <patternset>
        <include name="somepath_in_jar/somefile.ext" />
    </patternset>
</unjar>

but the somefile gets extracted to:

some_dest_path/somepath_in_jar/somefile.ext

when I want the file to get extracted to:

some_dest_path/somefile.ext

ie without dragging the path it was packaged with along with the process

How can I extract a file from a jar without having the extracted file include the path it was packaged with?


Solution

  • Try to use a mapper

    <unjar dest="some_dest_path" overwrite="true" src="somejar.jar">
      <patternset>
        <include name="somepath_in_jar/somefile.ext" />
      </patternset>
      <mapper type="flatten"/>
    </unjar>
    

    see ant mapper