Reputation: 83
My ant build file looks like this:
<project name="Algorithm" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="main-class" value="ye.tian.Main"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="lib.dir" value="lib"/>
<path id="myclasspath">
<fileset dir="${lib.dir}" includes="*.jar"/>
</path>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="myclasspath"/>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" classpathref="myclasspath" fork="true"/>
</target>
My project structure is: root folder with two folders inside named src and lib. Lib contains all the jar libraries and src - packages with java files.
Running the ant run
gives an error:
run:
[java] Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/type/TypeReference
Which i understand can not find library jars named Jackson which are under lib folder... My linking must be wrong. Any advice?
Thank!
UPDATE: Updated build.xml file with the suggestion from @AR.3 still the same issue
Upvotes: 0
Views: 2473
Reputation: 145
Make all the paths in all the properties absolute (by prefixing src.dir
, build.dir
and lib.dir
with ${basedir}/
). Thus you don't have to rely on working directory. <java>
task you run in run
target might use ${jar.dir}
as a working directory and your classpath (which is resolved as a relative path) would point to non-existing build/jar/lib/*.jar
.
<property name="src.dir" value="${basedir}/src"/>
<property name="build.dir" value="${basedir}/build"/>
<property name="lib.dir" value="${basedir}/lib"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="main-class" value="ye.tian.Main"/>
<property name="jar.dir" value="${build.dir}/jar"/>
Upvotes: 0