File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes why is log4j not working in executable jar? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "why is log4j not working in executable jar?" Watch "why is log4j not working in executable jar?" New topic
Author

why is log4j not working in executable jar?

Bob Peterson
Ranch Hand

Joined: Jul 30, 2004
Posts: 47
I've got a project that I jar into an executable jar with ant. I then zip up the executable jar along with the dependent jars it needs as well as a couple text files it reads. I've got the dependent jars listed in the class-path of the manifest file, the program can read the text files, all that appears to be working. It is structured in the zip file so that the executable jar, the dependent jars, and the text files are all in the same directory, like so:

/unzippedDir
myExecutable.jar
file1.txt
file2.txt
log4j.xml
commons-httpclient-3.1.jar
log4j-1.2.15.jar
other jars, etc.

Now I'm trying to enable logging because the user is having issues that I can't reproduce, so I'd like to be able to create logs that he can send me.

The logging works fine when run from Eclipse (it's a swing app). But there's no logging when run from the executable jar. I've put log4j.xml into the same directory as everything else listed above, and added log4j.xml to the class-path of the manifest file.

What am I missing?

Thanks
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Can you post the contents of your Manifest file please


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Bob Peterson
Ranch Hand

Joined: Jul 30, 2004
Posts: 47
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hmm, that looks OK, I assume you're running java -jar to execute your app?
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Oh also, can you try removing the log4j.xml and make sure that the common-logging is using log4j (you should see a message print out that there's no log4j configuration file), something like:

log4j:WARN No appenders could be found for logger (com.example.App).
log4j:WARN Please initialize the log4j system properly.
Bob Peterson
Ranch Hand

Joined: Jul 30, 2004
Posts: 47
No, I'm just double-clicking on the executable jar in a windows explorer view.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Try running the jar file from the command prompt with the java -jar command and see what output it gives
[ August 27, 2008: Message edited by: Martijn Verburg ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

The classpath is supposed to be a list of directories and jar files. You can't put individual files into the classpath. That's why your log4j.xml file isn't in the classpath, the way you have things set up. Try putting the directory "." into the classpath.
Bob Peterson
Ranch Hand

Joined: Jul 30, 2004
Posts: 47
Wohoo, that did it! (putting directory "." in the classpath)

Thanks Paul! Thanks also to Martijn for his quick responses.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why is log4j not working in executable jar?
 
Similar Threads
Classpath required on client\server?? Please suggest
Problem with executable jar file
Jars inside one jar?
Running jar from anywhere
jar files