I'm using ANT for creating a JAR file of my application. As I read, I should put the external Jars I need as arguments from the command line, but I want to build a Manifest file.
This is my build.xml file (only the part in which I build the jar)
<!-- Build jar from classes -->
<target name="jar" depends="compile" description="Build a jar file.">
<manifestclasspath property="jar.classpath" jarfile="${target.build.main}/main">
<classpath>
<fileset dir="${target.build.main}/lib" includes="*.jar"/>
</classpath>
</manifestclasspath>
<jar destfile="${target.dist}/configuration-deployer.jar" basedir="${target.build.main}">
<manifest>
<attribute name="Main-Class" value="${dist.main.class}" />
<attribute name="Class-Path" value="${jar.classpath}" />
</manifest>
</jar>
</target>
Now this is an extract of the manifest file
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.6.0_45-b06 (Sun Microsystems Inc.)
Main-Class: com.sap.coas.deployer.StoreInstanceOnMove
Class-Path: lib/ConfigurationMetamodel-1.jar lib/Consumer_api-1.jar li
b/FunctionalSystemMetaModel-1.jar lib/WS_api-1.jar lib/activemq-core-
5.7.0.jar lib/activemq-protobuf-1.1.jar ..... other jar
If I open the JAR generated, I can see the manifest inside META-INF folder, and the lib folder containes all the libraries. So the structure of the JAR is this one:
/META-INF/manifest.mf
/lib/ConfigurationMetamodel-1.jar
/lib/otherJar.jar ........
But when I try to run
java -jar myJar.jar
I got the ClassNotFoundException, and I'm sure that the jar containing the class that throw the exception is in the lib folder.
Thanks!