File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Problems Running Jar using ant" Watch "Problems Running Jar using ant" New topic
Author

Problems Running Jar using ant

seshu Palamanti
Ranch Hand

Joined: Jul 03, 2004
Posts: 59
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
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
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.).


Ping & DNS - updated with new look and Ping home screen widget
seshu Palamanti
Ranch Hand

Joined: Jul 03, 2004
Posts: 59
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems Running Jar using ant
 
Similar Threads
ejb on Weblogic7
ant file not running
Ant Build Successful but neither jar file nor build folder created ?
Javac error
Howto run specific JUnit tests in ant?