Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract .class files from .jar files?

Tags:

ant

A quick question: I like the look of this bit of Ant:

<fileset dir="${lib}">  
   <patternset refid="myPattern" />  
</fileset>

So I could use this e.g. to copy a few .jar files from ${lib} that match myPattern.

What if what I really want is to look into each .jar in ${lib} and select only .class files that match myPattern?

like image 911
seminolas Avatar asked Feb 28 '11 16:02

seminolas


2 Answers

The unjar task does pretty much what you want here out of the box. Use a fileset to specify the jar files you want to extract from, and a patternset to specify which files to extract.

<unjar dest="${dest.dir}">
  <patternset refid="myPattern" />
  <fileset dir="${lib}" includes="*.jar" />
</unjar>
like image 68
matt Avatar answered Nov 01 '22 15:11

matt


You can use the archives resource collection to extract several files from multiple archives:

<copy todir="somedir">
    <restrict>
        <!-- This is just an example, you can use any restriction -->
        <name name="somePattern"/> 
            <archives>
                <zips>
                    <fileset dir="${lib}" includes="**/*.jar" />
                </zips>
        </archives>
    </restrict>
</copy>
like image 25
Garns Avatar answered Nov 01 '22 17:11

Garns