This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems Running Jar using ant

 
seshu Palamanti
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
clean:
[delete] Deleting directory C:\Hello\Test\build
compile:
[mkdir] Created dir: C:\Hello\Test\build\classes
[javac] Compiling 1 source file to C:\Hello\Test\build\classes
jar:
[mkdir] Created dir: C:\Hello\Test\build\jar
[jar] Building jar: C:\Hello\Test\build\jar\HelloWorld.jar
run:
[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
main:
BUILD SUCCESSFUL
Total time: 1 second
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"/>
<classpath>
<pathelement location="${jar.dir}/${ant.project.name}.jar"/>
<pathelement path="${lib.dir}/log4j-1.2.13.jar"/>
<pathelement path="${lib.dir}/fame2_full.jar"/>
</classpath>
</java>

So i included the required jar with pathelement that seems to have solved the problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic