File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4j listener with ant

 
Joshua Antony
Ranch Hand
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just started learning log4j.
I wanted to create log4j listener for my build file, hence started with the small one.

is the build file.

I have log4j.properties present in the root of the project directory.
The content of log4j.properties is as below:


I have also placed this property file in a jar and added the jar to the classpath.

When I run the build file with the below arguments


I get the following exception:

BUILD FAILED
java.lang.NoClassDefFoundError: org/apache/log4j/Category
at org.apache.tools.ant.listener.Log4jListener.<init>(Log4jListener.java:43)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at java.lang.Class.newInstance0(Class.java:350)
at java.lang.Class.newInstance(Class.java:303)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.addBuildListeners(InternalAntRunner.java:156)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:338)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

Total time: 63 milliseconds


Where am I going wrong ? , Am I doing something really silly ?

Kind Regards,
Joshua
 
Jan Cumps
Bartender
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Ant's manual:
To use Log4j you will need the Log4j jar file and a 'log4j.properties' configuration file. Both should be placed somewhere in your Ant classpath.
It seems that you interpreted thez instructions like this: I have also placed this property file in a jar and added the jar to the classpath.But Ant expects that you place the Log4j jar file in the classpath. The file can be downloaded from the log4j project site.

Summary:

1: You need to add the -lib option:2:You can remove the jar file with the property file. You already have it as a properties file in the project root.

3: You need to make the log4j.jar file available in ant's classpath
The manual gives you the options on how to add a jar to Ant's classpath.

Regards, Jan
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic