Re: Elementary question

2003-09-08 Thread Paul Smith
Could you not place the configuration file in the root of the
/WEB-INF/classes/ ?  Log4j will automatically find log4j.xml or
log4j.properties if it is located there.

Alternatively you could use the
Thread.currentThread.getContextClassLoader(), this should work well
inside a Webapp.

cheers,

Paul Smith

On Mon, 2003-09-08 at 12:23, Bhamidi Krishna wrote:
 Hi,
 
 I am trying to configure log4j for an app. Currently, I have deployed 
 it on Tomcat. My code snippet is -
 
 ..
 String configFileName = com.common.logger.xml;
 URL url = null;
 Context ctx=null;
 ctx = new InitialContext();
 url = ctx.getClass().getResource(configFileName); 
 .
 
 I put the xml file under a directory structure under classes in my 
 web-app. The issue is that the URL is null. 
 
 I also tried other options like making the string 
 \com\common\logger.xml and com\common\logger.xml
 
 Another approach I tried was to get Thread.currentThread.getClassLoader
 and read the URL from there, I get a vague null pointer exception and 
 zip exception.
 
 I am sorry if this is a very elementary question, but I could not find 
 any solutions in the lists also. 
 
 Krishna.
 
 
 
 -
 Do you Yahoo!?
 Yahoo! SiteBuilder - Free, easy-to-use web site design software


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Elementary question

2003-09-07 Thread Bhamidi Krishna
Hi,

I am trying to configure log4j for an app. Currently, I have deployed 
it on Tomcat. My code snippet is -

..
String configFileName = com.common.logger.xml;
URL url = null;
Context ctx=null;
ctx = new InitialContext();
url = ctx.getClass().getResource(configFileName); 
.

I put the xml file under a directory structure under classes in my 
web-app. The issue is that the URL is null. 

I also tried other options like making the string 
\com\common\logger.xml and com\common\logger.xml

Another approach I tried was to get Thread.currentThread.getClassLoader
and read the URL from there, I get a vague null pointer exception and 
zip exception.

I am sorry if this is a very elementary question, but I could not find 
any solutions in the lists also. 

Krishna.



-
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

Re: Elementary question

2003-09-07 Thread Jacob Kjome
Try this...

String configFileName = /com/common/logger.xml;

Always use forward slashes when dealing with class loader paths.  These are 
Java packages, not system directories (even though they look similar).

One other thing.  Where is the class you are using to load the logger.xml 
file?  Is it in the same package as logger.xml (actually, I just noticed it 
is the InitialContext class, so the answer is no, it isn't in the same 
package, but anyway...)?  If so, then just do..

String configFileName = logger.xml;

When using the getResource() method from the Class class, resources are 
relative to the class.  Notice in the first example that I overrode this 
the relative path by including a preceding forward slash which makes it 
look for the resource starting from the root package.  You can also use the 
ClassLoader.getResource() method and remove the preceding forward slash to 
do the same thing.

Jake

At 07:23 PM 9/7/2003 -0700, you wrote:
Hi,

I am trying to configure log4j for an app. Currently, I have deployed
it on Tomcat. My code snippet is -
..
String configFileName = com.common.logger.xml;
URL url = null;
Context ctx=null;
ctx = new InitialContext();
url = ctx.getClass().getResource(configFileName);
.
I put the xml file under a directory structure under classes in my
web-app. The issue is that the URL is null.
I also tried other options like making the string
\com\common\logger.xml and com\common\logger.xml
Another approach I tried was to get Thread.currentThread.getClassLoader
and read the URL from there, I get a vague null pointer exception and
zip exception.
I am sorry if this is a very elementary question, but I could not find
any solutions in the lists also.
Krishna.



-
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Elementary question

2003-09-07 Thread Bhamidi Krishna
Hi Jake,
 
thankou for the mail. I tried with forward slashes \, but the context does not seem 
to like it, I keep gettin the URL as null.

Jacob Kjome [EMAIL PROTECTED] wrote:

Try this...

String configFileName = /com/common/logger.xml;

Always use forward slashes when dealing with class loader paths. These are 
Java packages, not system directories (even though they look similar).

One other thing. Where is the class you are using to load the logger.xml 
file? Is it in the same package as logger.xml (actually, I just noticed it 
is the InitialContext class, so the answer is no, it isn't in the same 
package, but anyway...)? If so, then just do..

String configFileName = logger.xml;

When using the getResource() method from the Class class, resources are 
relative to the class. Notice in the first example that I overrode this 
the relative path by including a preceding forward slash which makes it 
look for the resource starting from the root package. You can also use the 
ClassLoader.getResource() method and remove the preceding forward slash to 
do the same thing.

Jake

At 07:23 PM 9/7/2003 -0700, you wrote:
Hi,

I am trying to configure log4j for an app. Currently, I have deployed
it on Tomcat. My code snippet is -

..
String configFileName = com.common.logger.xml;
URL url = null;
Context ctx=null;
ctx = new InitialContext();
url = ctx.getClass().getResource(configFileName);
.

I put the xml file under a directory structure under classes in my
web-app. The issue is that the URL is null.

I also tried other options like making the string
\com\common\logger.xml and com\common\logger.xml

Another approach I tried was to get Thread.currentThread.getClassLoader
and read the URL from there, I get a vague null pointer exception and
zip exception.

I am sorry if this is a very elementary question, but I could not find
any solutions in the lists also.

Krishna.



-
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

Re: Elementary question

2003-09-07 Thread Jacob Kjome
InitialContext is probably loaded from a parent class loader and can't see 
the resource in your child class loader.  Why are you using InitialContext 
in this situation anyway?  Just use the class you are performing this 
from.  Let's call it MyClass

in a static context...
MyClass.class.getResource(configFileName);
in an object context...
this.getClass().getResource(configFileName);
There is no reason this shouldn't work.

Jake

At 08:06 PM 9/7/2003 -0700, you wrote:
Hi Jake,

thankou for the mail. I tried with forward slashes \, but the context 
does not seem to like it, I keep gettin the URL as null.

Jacob Kjome [EMAIL PROTECTED] wrote:

Try this...

String configFileName = /com/common/logger.xml;

Always use forward slashes when dealing with class loader paths. These are
Java packages, not system directories (even though they look similar).
One other thing. Where is the class you are using to load the logger.xml
file? Is it in the same package as logger.xml (actually, I just noticed it
is the InitialContext class, so the answer is no, it isn't in the same
package, but anyway...)? If so, then just do..
String configFileName = logger.xml;

When using the getResource() method from the Class class, resources are
relative to the class. Notice in the first example that I overrode this
the relative path by including a preceding forward slash which makes it
look for the resource starting from the root package. You can also use the
ClassLoader.getResource() method and remove the preceding forward slash to
do the same thing.
Jake

At 07:23 PM 9/7/2003 -0700, you wrote:
Hi,

I am trying to configure log4j for an app. Currently, I have deployed
it on Tomcat. My code snippet is -

..
String configFileName = com.common.logger.xml;
URL url = null;
Context ctx=null;
ctx = new InitialContext();
url = ctx.getClass().getResource(configFileName);
.

I put the xml file under a directory structure under classes in my
web-app. The issue is that the URL is null.

I also tried other options like making the string
\com\common\logger.xml and com\common\logger.xml

Another approach I tried was to get Thread.currentThread.getClassLoader
and read the URL from there, I get a vague null pointer exception and
zip exception.

I am sorry if this is a very elementary question, but I could not find
any solutions in the lists also.

Krishna.



-
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
-
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]