Ant Retrieving Classes in a Jar

Possible duplicate:
A clean way to combine multiple cans? Ant preferred

When I export the jar file from eclipse, one of the options I get is to extract the class files from the dependency jars into my last jar (other options include just packing the jars in my last jar or just leaving everything outside my last jar ) Of course, there is a warning about licensing issues.

So, here is the question - what is the equivilant of this in apache ant? How can I make ant extract classes from the jars that my program depends on and repack them in my last jar?

+4
source share
1 answer

Try something like this:

<?xml version="1.0"?> <project name="blah" basedir="." default="jar"> <target name="init"> <property name="build" value="./build" /> <property name="srcdir" value="./src" /> <property name="lib.dir" value="./lib" /> <property name="dist" value="./dist" /> <property name="docs" value="./docs" /> <property name="debug" value="true" /> <path id="project.class.path"> <pathelement path="${java.class.path}" /> <fileset dir="${lib.dir}"> <include name="*.jar" /> </fileset> </path> </target> <target name="compile" depends="init"> <mkdir dir="${build}" /> <javac debug="${debug}" optimize="${optimize}" destdir="${build}" deprecation="${deprecation}" source="1.6" target="1.6"> <src path="${srcdir}" /> <classpath refid="project.class.path" /> </javac> </target> <target name="jar" depends="compile"> <mkdir dir="${dist}" /> <jar destfile="${dist}/${ant.project.name}.jar"> <fileset dir="${build}"> <include name="com/blah/blah/*.class" /> </fileset> </jar> </target> <target name="package" depends="compile, jar"> <jar destfile="${dist}/${ant.project.name}-release.jar" basedir="${build}" includes="**/*.*"> <manifest> <attribute name="Main-Class" value="com.blah.blah.Main" /> </manifest> <zipgroupfileset dir="${lib.dir}" includes="*.jar" /> <zipgroupfileset dir="${dist}" includes="${ant.project.name}.jar" /> </jar> </target> </project> 

Then you will go:

ant package

To create a single jar file with all the classes in the lib folder.

0
source

All Articles