aspose file tools*
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
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "log4j listener with ant" Watch "log4j listener with ant" New topic
Author

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:

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


SCJP,SCWCD, Into ATG now!
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2477
    
    7

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


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: log4j listener with ant
 
Similar Threads
ant exception
Hibernate - Confusing Configuration Errors
using ant with Log4jListener - how do I filter out the task events
Problem getting log4j.properties picked up when I use security.manager ?
Ant does not output property file in classes folder.