Note that there are some explanatory texts on larger screens.

plurals
  1. POIncluding external jar-files in a new jar-file build with Ant
    text
    copied!<p>I have just 'inherited' a Java-project and not coming from a Java-background I am a little lost at times. Eclipse is used to debug and run the application during development. I have through Eclipse succeeded in creating a .jar-file that 'includes' all the required external jars like Log4J, xmlrpc-server, etc. This big .jar can then be run successfully using:</p> <pre><code>java -jar myjar.jar </code></pre> <p>My next step is to automate builds using Ant (version 1.7.1) so I don't have to involve Eclipse to do builds and deployment. This has proven to be a challenge due to my lacking java-knowledge. The root of the project looks like this:</p> <pre><code>|-&gt; jars (where external jars have been placed) |-&gt; java | |-&gt; bin (where the finished .class / .jars are placed) | |-&gt; src (Where code lives) | |-&gt; ++files like build.xml etc |-&gt; sql (you guessed it; sql! ) </code></pre> <p>My build.xml contains the following:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt; &lt;project basedir="." default="build" name="Seraph"&gt; &lt;property environment="env"/&gt; &lt;property name="debuglevel" value="source,lines,vars"/&gt; &lt;property name="target" value="1.6"/&gt; &lt;property name="source" value="1.6"/&gt; &lt;property name="build.dir" value="bin"/&gt; &lt;property name="src.dir" value="src"/&gt; &lt;property name="lib.dir" value="../jars"/&gt; &lt;property name="classes.dir" value="${build.dir}/classes"/&gt; &lt;property name="jar.dir" value="${build.dir}/jar"/&gt; &lt;property name="jar.file" value="${jar.dir}/seraph.jar"/&gt; &lt;property name="manifest.file" value="${jar.dir}/MANIFEST.MF"/&gt; &lt;property name="main.class" value="no.easyconnect.seraph.core.SeraphCore"/&gt; &lt;path id="external.jars"&gt; &lt;fileset dir="${lib.dir}" includes="**/*.jar"/&gt; &lt;/path&gt; &lt;path id="project.classpath"&gt; &lt;pathelement location="${src.dir}"/&gt; &lt;path refid="external.jars" /&gt; &lt;/path&gt; &lt;target name="init"&gt; &lt;mkdir dir="${build.dir}"/&gt; &lt;mkdir dir="${classes.dir}"/&gt; &lt;mkdir dir="${jar.dir}"/&gt; &lt;copy includeemptydirs="false" todir="${build.dir}"&gt; &lt;fileset dir="${src.dir}"&gt; &lt;exclude name="**/*.launch"/&gt; &lt;exclude name="**/*.java"/&gt; &lt;/fileset&gt; &lt;/copy&gt; &lt;/target&gt; &lt;target name="clean"&gt; &lt;delete dir="${build.dir}"/&gt; &lt;/target&gt; &lt;target name="cleanall" depends="clean"/&gt; &lt;target name="build" depends="init"&gt; &lt;echo message="${ant.project.name}: ${ant.file}"/&gt; &lt;javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}" classpathref="project.classpath"&gt; &lt;src path="${src.dir}"/&gt; &lt;/javac&gt; &lt;/target&gt; &lt;target name="build-jar" depends="build"&gt; &lt;delete file="${jar.file}" /&gt; &lt;delete file="${manifest.file}" /&gt; &lt;manifest file="${manifest.file}" &gt; &lt;attribute name="built-by" value="${user.name}" /&gt; &lt;attribute name="Main-Class" value="${main.class}" /&gt; &lt;/manifest&gt; &lt;jar destfile="${jar.file}" basedir="${build.dir}" manifest="${manifest.file}"&gt; &lt;fileset dir="${classes.dir}" includes="**/*.class" /&gt; &lt;fileset dir="${lib.dir}" includes="**/*.jar" /&gt; &lt;/jar&gt; &lt;/target&gt; &lt;/project&gt; </code></pre> <p>I then run: ant clean build-jar</p> <p>and a file named seraph.jar is placed in the java/bin/jar-directory. I then try to run this jar using the following command: java -jar bin/jar/seraph.jar</p> <p>The result is this output at the console:</p> <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger at no.easyconnect.seraph.core.SeraphCore.&lt;clinit&gt;(SeraphCore.java:23) Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) ... 1 more Could not find the main class: no.easyconnect.seraph.core.SeraphCore. Program will exit. </code></pre> <p>I suspect that I have done something amazingly silly in the build.xml-file and have spent the better part of two days trying variations on the configuration, to no avail. Any help on getting this working is greatly appreciated.</p> <p>Oh, and I'm sorry if I left some crucial information out. This is my first time posting here at SO.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload