I tried to create a jar file from a java project, which uses some external jars. I created a lib folder and put all the jars I need there.
I run the project in eclipse by adding all the jars in the lib folder to the Build Path and it works ok.
When I try to create the jar with ant from build.xml, it seems ok, no error is shown.
When I try to run the jar, I get the message "Invalid or corupt jarfile".
In build.xml: I define the path to use for compiling:
<path id="project.classpath">
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>
This is the target for the compilation:
<target name="compile" depends="init" description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}">
<classpath refid="project.classpath"/>
</javac>
</target>
And this is the target for making the jar file:
<target name="dist" depends="compile" description="generate the distribution" >
<mkdir dir="${dist}"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/MyProject-${DSTAMP}.jar" basedir="${build}">
<manifest>
<attribute name="Main-Class" value="${main}" />
<attribute name="Class-Path:" value="lib/**/*.*"/>
</manifest>
<fileset dir="${src}" includes="images/**/*.*" />
</jar>
<echo file="${dist}/start.bat" message="java -jar MyProject-${DSTAMP}.jar" />
</target>
Can you please tell me what have I done wrong?