I'm an Apache Ant novice and I must produce a build file having a run task. The run task should execute the next command line statemenet

java -classpath C:/tmp/SYS/doodle.jar;C:/tmp/SYS/CTX.jar sys.ctx.doodle.Start

in which the sys.ctx.doodle.Start class is situated within the doodle.jar

My real question is: how do i add two elements inside a classpath? I've attempted the next:

<target name="run">
   <java jar="C:/tmp/SYS/doodle.jar" fork="true">
      <pathelement location="C:/tmp/SYS/doodle.jar"/>
      <pathelement path="sys.ctx.doodle.Start"/>
       <pathelement location="C:/tmp/SYS/CTX.jar"/>

However when performing it throws us a java.lang.NoClassDefFoundError

Any idea in which the problem might be?

You are able to transpose your command-line path in to the Ant [cde] task classpath attribute directly. Ant should take proper care of identifying that's made up of semicolon-delimited jar names.


Or specify it as being a nested element while you presently have:

<java classpath="C:/tmp/SYS/doodle.jar;C:/tmp/SYS/CTX.jar" ... >

The argument <java ... > <classpath> <pathelement path="C:/tmp/SYS/doodle.jar;C:/tmp/SYS/CTX.jar" /> </classpath> </java> appears like the title from the class you need to run. Make use of the sys.ctx.doodle.Start attribute to pass through that towards the classname task. Putting by using the classpath results in:


The <java classpath="C:/tmp/SYS/doodle.jar;C:/tmp/SYS/CTX.jar" classname="sys.ctx.doodle.Start" /> attribute ought to be used only when you wish to operate the jar incorporated for the reason that jar.

You've a lot of Main-Class elements. The thing you need is single <classpath> element such as this:


You will have to alter the <classpath> <pathelement location="C:/tmp/SYS/doodle.jar"/> <pathelement location="C:/tmp/SYS/CTX.jar"/> </classpath> tag such as this:


For adding multiple jars for your classpath reference utilizing a Filesetappears to become a clean method of doing it


<java jar="C:/tmp/SYS/doodle.jar" fork="true" classname="sys.ctx.doodle.Start">

Will prove to add all jars within the lib directory towards the classpath.