views:

26

answers:

2

Hi,

I need to load log4j.xml config file in my web to initialize logging. log4j.xml is in package com.test.config.

when in j2se java app code

InputStream input = ClassLoader.getSystemClassLoader().getResourceAsStream("com/test/config/log4j.xml");

resturns input stream but when I execute this in servlet it returns null. servlet is java web app deployed on glassfish 2.1

what's the difference?

+1  A: 

If the log4j.xml file is in a jar file, ensure that you've added the jar file to the servlet classpath in Glassfish.

Otherwise, if its in a directory, say resources/com/test/config you have to add the resources directory to your server classpath.

purecharger
A: 

You could try using the current thread's context class loader Thread.currentThread().getContextClassLoader() instead, I think this solved a similar issue for me once.

Fabian Steeg
I tried this and it works:) tnx! :)
Marko