You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Esteban González <eg...@outside.com.ar> on 2002/12/02 16:33:42 UTC

Tomcat 4.0.3 & getResourceAsStream

Hi!
I´ve just moved an old app that we had running using Jserv to tomcat4.0.3

But i have problems with this
    p = new Properties();
    InputStream is = p.getClass().getResourceAsStream("/icard.properties");
I keep getting null no matter where i put the icard.properties file.

i´ve placed icard.properties inside WEB-INF/lib and WEB-INF/classes and it´s
also on the classpath...

any workarounds to this issue?...  I´m trying not to use the java.io.*
approach...

----------------------------------
Esteban González

Departamento de Sistemas
ASSIST-CARD International


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re[2]: Tomcat 4.0.3 & getResourceAsStream

Posted by Jacob Kjome <ho...@visi.com>.
Hello Esteban,

It won't work with p.getClass... unless the resource you are trying to
load is in the classpath...meaning it must be within WEB-INF/classes
or WEB-INF/lib/somejar.jar and you wouldn't reference "WEB-INF".  The
classloader knows absolutely nothing about it.

If your resoruce was in the root of WEB-INF/classes (root of the
current classloader... also equivalent to putting the resource in a jar file, but
not inside a package in that jar file), the following will work:
p.getClass.getResourceAsStream("/myResource.properties");

This will work if your resource is located relative to the current
class "p" (same package as the class).
p.getClass.getResourceAsStream("myResource.properties");

This will work to find the resource anywhere in the current
classloader (make sure not to prefix with "/"):
p.getClass.getClassLoader.getResourceAsStream("myResource.properties");

This will work to find the resource even if it isn't in the same
classloader.  For instance, maybe it is in a parent classloader or a
child classloader relative to the current classloader (make sure not
to prefix with "/"):
Thread.currentThread().getContextClassLoader().getResourceAsStream("myResource.properties");

This will work to find the the resource using the servlet context and
fulfill your requirement to put all properties in WEB-INF/conf:
theServletConfig.getServletContext().getResourceAsStream("/WEB-INF/conf/myResource.properties");


For your purposes, you need the last one.  None of the others will
work unless your resource is in the classloader which WEB-INF/conf
isn't.

Jake

Monday, December 02, 2002, 9:59:28 AM, you wrote:

EG> Thanks for your help andreas.

EG> It didn´t work with p.getClass..

EG> i´m trying with getServletContext().

EG> But my idea is to have WEB-INF/conf   to place all .properties files.

EG> is that possible?...

EG> Best regards,
EG> Esteban

EG> ----- Original Message -----
EG> From: "Andreas Probst" <an...@gmx.net>
EG> To: "Tomcat Users List" <to...@jakarta.apache.org>
EG> Sent: Monday, December 02, 2002 12:57 PM
EG> Subject: Re: Tomcat 4.0.3 & getResourceAsStream


EG> Hi Esteban,

EG> try

EG> p.getClass().getResourceAsStream("/WEB-INF/icard.properties");
EG> (inside WEB-INF)
EG> or
EG> p.getClass().getResourceAsStream("/WEB-
EG> INF/classes/icard.properties");
EG> (inside classes)
EG> or
EG> p.getClass().getResourceAsStream("/WEB-
EG> INF/lib/icard.properties");
EG> (inside lib)

EG> If this doesn't work, try
EG> getServletContext().getResourceAsStream(...)
EG> This one will work.

EG> Good luck.

EG> Andreas

EG> On 2 Dec 2002 at 12:33, Esteban González wrote:

>> Hi!
>> I´ve just moved an old app that we had running using Jserv to
>> tomcat4.0.3
>>
>> But i have problems with this
>>     p = new Properties();
>>     InputStream is =
>>     p.getClass().getResourceAsStream("/icard.properties");
>> I keep getting null no matter where i put the icard.properties
>> file.
>>
>> i´ve placed icard.properties inside WEB-INF/lib and
>> WEB-INF/classes and it´s also on the classpath...
>>
>> any workarounds to this issue?...  I´m trying not to use the
>> java.io.* approach...
>>
>> ----------------------------------
>> Esteban González
>>
>> Departamento de Sistemas
>> ASSIST-CARD International
>>
>>
>> --
>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org> For
>> additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>>



EG> --
EG> To unsubscribe, e-mail:
EG> <ma...@jakarta.apache.org>
EG> For additional commands, e-mail:
EG> <ma...@jakarta.apache.org>


EG> --
EG> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
EG> For additional commands, e-mail: <ma...@jakarta.apache.org>



-- 
Best regards,
 Jacob                            mailto:hoju@visi.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: migration from jrun to tomcat

Posted by Pae Choi <pa...@earthlink.net>.
Just curious. Is your migration extending your app while preseving JRun or
planning to drop JRun when the migration is completed. Thanks.


Pae


> Hi All,
>
> I am new user to tomcat. I have my application in Jrun. I want to mirate
> to tomcat . It would be really helpful if anyone can tell me the necessary
> steps needed for the migration. It would be of great help .
>
> shyam
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


migration from jrun to tomcat

Posted by Shyama Gavulla <sh...@coe.neu.edu>.
Hi All,

I am new user to tomcat. I have my application in Jrun. I want to mirate
to tomcat . It would be really helpful if anyone can tell me the necessary
steps needed for the migration. It would be of great help .

shyam



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Tomcat 4.0.3 & getResourceAsStream

Posted by Andreas Probst <an...@gmx.net>.
Hi Esteban

I think if WEB-INF/classes works, any other directory there will 
work too.

Andreas

On 2 Dec 2002 at 12:59, Esteban González wrote:

> Thanks for your help andreas.
> 
> It didn´t work with p.getClass..
> 
> i´m trying with getServletContext().
> 
> But my idea is to have WEB-INF/conf   to place all .properties
> files.
> 
> is that possible?...
> 
> Best regards,
> Esteban
> 
> ----- Original Message -----
> From: "Andreas Probst" <an...@gmx.net>
> To: "Tomcat Users List" <to...@jakarta.apache.org>
> Sent: Monday, December 02, 2002 12:57 PM
> Subject: Re: Tomcat 4.0.3 & getResourceAsStream
> 
> 
> Hi Esteban,
> 
> try
> 
> p.getClass().getResourceAsStream("/WEB-INF/icard.properties");
> (inside WEB-INF) or p.getClass().getResourceAsStream("/WEB-
> INF/classes/icard.properties"); (inside classes) or
> p.getClass().getResourceAsStream("/WEB-
> INF/lib/icard.properties"); (inside lib)
> 
> If this doesn't work, try
> getServletContext().getResourceAsStream(...)
> This one will work.
> 
> Good luck.
> 
> Andreas
> 
> On 2 Dec 2002 at 12:33, Esteban González wrote:
> 
> > Hi!
> > I´ve just moved an old app that we had running using Jserv to
> > tomcat4.0.3
> >
> > But i have problems with this
> >     p = new Properties();
> >     InputStream is =
> >     p.getClass().getResourceAsStream("/icard.properties");
> > I keep getting null no matter where i put the icard.properties
> > file.
> >
> > i´ve placed icard.properties inside WEB-INF/lib and
> > WEB-INF/classes and it´s also on the classpath...
> >
> > any workarounds to this issue?...  I´m trying not to use the
> > java.io.* approach...
> >
> > ----------------------------------
> > Esteban González
> >
> > Departamento de Sistemas
> > ASSIST-CARD International
> >
> >


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Tomcat 4.0.3 & getResourceAsStream

Posted by Esteban González <eg...@outside.com.ar>.
Thanks for your help andreas.

It didn´t work with p.getClass..

i´m trying with getServletContext().

But my idea is to have WEB-INF/conf   to place all .properties files.

is that possible?...

Best regards,
Esteban

----- Original Message -----
From: "Andreas Probst" <an...@gmx.net>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Monday, December 02, 2002 12:57 PM
Subject: Re: Tomcat 4.0.3 & getResourceAsStream


Hi Esteban,

try

p.getClass().getResourceAsStream("/WEB-INF/icard.properties");
(inside WEB-INF)
or
p.getClass().getResourceAsStream("/WEB-
INF/classes/icard.properties");
(inside classes)
or
p.getClass().getResourceAsStream("/WEB-
INF/lib/icard.properties");
(inside lib)

If this doesn't work, try
getServletContext().getResourceAsStream(...)
This one will work.

Good luck.

Andreas

On 2 Dec 2002 at 12:33, Esteban González wrote:

> Hi!
> I´ve just moved an old app that we had running using Jserv to
> tomcat4.0.3
>
> But i have problems with this
>     p = new Properties();
>     InputStream is =
>     p.getClass().getResourceAsStream("/icard.properties");
> I keep getting null no matter where i put the icard.properties
> file.
>
> i´ve placed icard.properties inside WEB-INF/lib and
> WEB-INF/classes and it´s also on the classpath...
>
> any workarounds to this issue?...  I´m trying not to use the
> java.io.* approach...
>
> ----------------------------------
> Esteban González
>
> Departamento de Sistemas
> ASSIST-CARD International
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org> For
> additional commands, e-mail:
> <ma...@jakarta.apache.org>
>



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Tomcat 4.0.3 & getResourceAsStream

Posted by Andreas Probst <an...@gmx.net>.
Hi Esteban,

try 

p.getClass().getResourceAsStream("/WEB-INF/icard.properties");
(inside WEB-INF)
or
p.getClass().getResourceAsStream("/WEB-
INF/classes/icard.properties");
(inside classes)
or
p.getClass().getResourceAsStream("/WEB-
INF/lib/icard.properties");
(inside lib)

If this doesn't work, try 
getServletContext().getResourceAsStream(...)
This one will work.

Good luck.

Andreas

On 2 Dec 2002 at 12:33, Esteban González wrote:

> Hi!
> I´ve just moved an old app that we had running using Jserv to
> tomcat4.0.3
> 
> But i have problems with this
>     p = new Properties();
>     InputStream is =
>     p.getClass().getResourceAsStream("/icard.properties");
> I keep getting null no matter where i put the icard.properties
> file.
> 
> i´ve placed icard.properties inside WEB-INF/lib and
> WEB-INF/classes and it´s also on the classpath...
> 
> any workarounds to this issue?...  I´m trying not to use the
> java.io.* approach...
> 
> ----------------------------------
> Esteban González
> 
> Departamento de Sistemas
> ASSIST-CARD International
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org> For
> additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>