java.lang.NoClassDefFoundError ANT build java.lang.NoClassDefFoundError ANT build selenium selenium

java.lang.NoClassDefFoundError ANT build


The classpath is needed also when running the Jar file so that the JVM could find library classes. However, when using the jar attribute in the java task, "all classpath settings are ignored" (see https://ant.apache.org/manual/Tasks/java.html). The simplest way is to specify the main class and add the compiled Jar along with the library Jars located in the RunningPowerJars directory:

<target name="run" description="Run the jar file" depends="jar" >    <java classname="RunningPower" fork="true">       <classpath>            <pathelement location="build/jar/RunningPower.jar"/>            <fileset dir="${lib.dir}">                <include name="**/*.jar" />            </fileset>        </classpath>   </java></target>

An unrelated note is that you could use the properties defined in init throughout the buildfile. For example, in the jar target you can use ${classes.dir} instead of repeating build/class.

It still doesn't make sense why the build would fail if the classpath element is added inside the java task when using the jar attribute. Although it is ignored, it is weird that it is failing with the "failed to create task or type" error.


Consider that when you use the -jar parameter using the java.exe in command line the classpath parameter is ignored, that also happens with the java task in ant.

So, what you must do is to provide the libraries you need to have available to the process launching that ant and that will suffice.

Once said that... where should you add those libraries then ? if you're launching from eclipse, you may add them on Window->preferences under Ant->Runtime->Global Entries.

If you're using some C.I. server like jenkins you could add them on numerous ways, I cannot give a direct answer because there could be many.

There is also an alternative. You may declare the dependency on the .jar MANIFEST.MF and put it under /lib or whatever inside that jar.