This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes Problems Running Jar using ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Problems Running Jar using ant" Watch "Problems Running Jar using ant" New topic

Problems Running Jar using ant

seshu Palamanti
Ranch Hand

Joined: Jul 03, 2004
Posts: 63
I am new to ant working on simple hello world app using ant...i am able to get to creating the jar....but unable to run cause it does not find the log4j.jar the code runs fine with the eclipse and the log4j is in classpath...but ant running jar does not find the log4j or any other jar files.

Buildfile: C:\Hello\Test\build.xml
[echo] Hello, World
[delete] Deleting directory C:\Hello\Test\build
[mkdir] Created dir: C:\Hello\Test\build\classes
[javac] Compiling 1 source file to C:\Hello\Test\build\classes
[mkdir] Created dir: C:\Hello\Test\build\jar
[jar] Building jar: C:\Hello\Test\build\jar\HelloWorld.jar
[java] java.lang.NoClassDefFoundError: org/apache/log4j/Logger
[java] at us.Test.test.ant.HelloWorld.<clinit>(Unknown Source)
[java] Exception in thread "main"
[java] Java Result: 1
Total time: 1 second
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Ant expects all jar files in the lib directory inside the ANT_HOME directory. It does not use the standard classpath, so you should copy the required jar files to that directory. Alternatively, you could install those files systemwide (in the ...jre/lib/ext directory under Windows, e.g.).
seshu Palamanti
Ranch Hand

Joined: Jul 03, 2004
Posts: 63
Thanks Mr. Ulf Dittmer for your reply this is what i did to solve the problem

<target name="run" depends="jar">
<java classname="${main-class}">
<arg value="-h"/>
<pathelement location="${jar.dir}/${}.jar"/>
<pathelement path="${lib.dir}/log4j-1.2.13.jar"/>
<pathelement path="${lib.dir}/fame2_full.jar"/>

So i included the required jar with pathelement that seems to have solved the problem.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Problems Running Jar using ant
jQuery in Action, 3rd edition