Meaningless Drivel is fun!
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 REST with Spring (video course) this week in the Spring 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 present in the root of the project directory.
The content of 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 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
at java.lang.reflect.Constructor.newInstance(
at java.lang.Class.newInstance0(
at java.lang.Class.newInstance(
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.addBuildListeners(
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(

Total time: 63 milliseconds

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

Kind Regards,

Jan Cumps

Joined: Dec 20, 2006
Posts: 2562

From Ant's manual:
To use Log4j you will need the Log4j jar file and a '' 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
I agree. Here's the link:
subject: log4j listener with ant
It's not a secret anymore!