wood burning stoves 2.0
The moose likes Ant, Maven and Other Build Tools and the fly likes log4j listener with ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "log4j listener with ant" Watch "log4j listener with ant" New topic

log4j listener with ant

Joshua Antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 254
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:

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,

Jan Cumps

Joined: Dec 20, 2006
Posts: 2526

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.


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

OCUP UML fundamental and ITIL foundation
youtube channel
Don't get me started about those stupid light bulbs.
subject: log4j listener with ant