You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-user@jakarta.apache.org by Troels Rossing <tr...@qualiware.com> on 2002/10/04 09:29:41 UTC
Help on simple properties file access
Hi
I am new to Slide and Servlets/JSP.
I have created a taglib with a tag Message which reads a properties
file.
But I can't get access to my properties file.
I deploy the app. In a war file and the structure is as follows.
myApp
- myJsp
- classes
- myprop.properties
- Message.class
- web-inf
- mylib.tld
- web.xml
My only problem is the file access for myprop, everything else works
fine, I use the following to access the file.
InputStream thefile =
this.getClass().getResourceAsStream("/myprop.properties");
I have tried almost any combination of paths (the above is just one of
them), and the only time I got it to works was when I copied the
properties file to the shared/classes dir of the tomcat server and when
I used the absolute path.
What is the relative root dir to my application, when I deploy the war.
Hope someone can help on this issue.
Regards
Troels
www.Qualiware.com
RE: Help on simple properties file access
Posted by Troels Rossing <tr...@qualiware.com>.
Thanks for your help :-)
I found that the cause of my problem is the fact that I try to access
the properties file from a class (extends TagSupport) in my taglib. If I
move the same code to a servlet as you described everything works
perfect.
Troels
-----Original Message-----
From: Luca Zago [mailto:zagoluc@libero.it]
Sent: 4. oktober 2002 11:30
To: Slide Users Mailing List
Subject: Re: Help on simple properties file access
I am agree with Andreas, but if you don't want to use the path
/WEB-INF/myFile.properties
Properties files can be found exactly like any other classes, if there
are present in the classpath, the classpath for your web-app starts from
/WEB-INF/classes, then if you put the file in the path
/WEB-INF/classes/myFile.properties, you can access it with the code:
servletContext.getResourceAsStream("myFile.properties");
or
this.getClass().getResourceAsStream("myFile.properties");
as you like.
Bye
Andreas Probst wrote:
> Hi Troels,
>
> I put my properties file into /WEB-INF of my web app. I access
> it with
>
> InputStream dmsPropsIn =
> servletContext.getResourceAsStream("/WEB-INF/dms.properties");
>
> (servletContext is a variable initialised inside my servlet's
> init(): ServletContext servletContext = getServletContext();)
>
> I don't know whether this works with JSP.
>
> Your classes directory isn't below WEB-INF. I think it should be
> there. Make sure WEB-INF is in capital letters. In case your
> config is working, put /classes before the properties file name.
>
> I think pathToTomcat/webapps/tomcat-docs/appdev/index.html is a
> good starting point if you're new to servlets and web app
> development.
>
> Hope that helps
>
> Andreas
>
>
> On 4 Oct 2002 at 9:29, Troels Rossing wrote:
>
>
>>Hi
>>
>>
>>
>>I am new to Slide and Servlets/JSP.
>>
>>
>>
>>I have created a taglib with a tag Message which reads a properties
>>file.
>>
>>
>>
>>But I can't get access to my properties file.
>>
>>
>>
>>I deploy the app. In a war file and the structure is as follows.
>>
>>
>>
>>myApp
>>
>>- myJsp
>>
>>- classes
>>
>> - myprop.properties
>>
>> - Message.class
>>
>>- web-inf
>>
>> - mylib.tld
>>
>> - web.xml
>>
>>
>>
>>My only problem is the file access for myprop, everything else works
>>fine, I use the following to access the file.
>>
>>
>>
>> InputStream thefile =
>>this.getClass().getResourceAsStream("/myprop.properties");
>>
>>
>>
>>I have tried almost any combination of paths (the above is just one of
>>them), and the only time I got it to works was when I copied the
>>properties file to the shared/classes dir of the tomcat server and
when
>>I used the absolute path.
>>
>>
>>
>>What is the relative root dir to my application, when I deploy the
war.
>>
>>
>>
>>
>>
>>Hope someone can help on this issue.
>>
>>
>>
>>
>>
>>Regards
>>
>>
>>
>>Troels
>>
>>
>>
>>www.Qualiware.com
>>
>>
>>
>>
>
>
>
>
> --
> 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: Help on simple properties file access
Posted by Luca Zago <za...@libero.it>.
I am agree with Andreas, but if you don't want to use the path
/WEB-INF/myFile.properties
Properties files can be found exactly like any other classes, if there
are present in the classpath, the classpath for your web-app starts from
/WEB-INF/classes, then if you put the file in the path
/WEB-INF/classes/myFile.properties, you can access it with the code:
servletContext.getResourceAsStream("myFile.properties");
or
this.getClass().getResourceAsStream("myFile.properties");
as you like.
Bye
Andreas Probst wrote:
> Hi Troels,
>
> I put my properties file into /WEB-INF of my web app. I access
> it with
>
> InputStream dmsPropsIn =
> servletContext.getResourceAsStream("/WEB-INF/dms.properties");
>
> (servletContext is a variable initialised inside my servlet's
> init(): ServletContext servletContext = getServletContext();)
>
> I don't know whether this works with JSP.
>
> Your classes directory isn't below WEB-INF. I think it should be
> there. Make sure WEB-INF is in capital letters. In case your
> config is working, put /classes before the properties file name.
>
> I think pathToTomcat/webapps/tomcat-docs/appdev/index.html is a
> good starting point if you're new to servlets and web app
> development.
>
> Hope that helps
>
> Andreas
>
>
> On 4 Oct 2002 at 9:29, Troels Rossing wrote:
>
>
>>Hi
>>
>>
>>
>>I am new to Slide and Servlets/JSP.
>>
>>
>>
>>I have created a taglib with a tag Message which reads a properties
>>file.
>>
>>
>>
>>But I can't get access to my properties file.
>>
>>
>>
>>I deploy the app. In a war file and the structure is as follows.
>>
>>
>>
>>myApp
>>
>>- myJsp
>>
>>- classes
>>
>> - myprop.properties
>>
>> - Message.class
>>
>>- web-inf
>>
>> - mylib.tld
>>
>> - web.xml
>>
>>
>>
>>My only problem is the file access for myprop, everything else works
>>fine, I use the following to access the file.
>>
>>
>>
>> InputStream thefile =
>>this.getClass().getResourceAsStream("/myprop.properties");
>>
>>
>>
>>I have tried almost any combination of paths (the above is just one of
>>them), and the only time I got it to works was when I copied the
>>properties file to the shared/classes dir of the tomcat server and when
>>I used the absolute path.
>>
>>
>>
>>What is the relative root dir to my application, when I deploy the war.
>>
>>
>>
>>
>>
>>Hope someone can help on this issue.
>>
>>
>>
>>
>>
>>Regards
>>
>>
>>
>>Troels
>>
>>
>>
>>www.Qualiware.com
>>
>>
>>
>>
>
>
>
>
> --
> 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: Help on simple properties file access
Posted by Andreas Probst <an...@gmx.net>.
Hi Troels,
I put my properties file into /WEB-INF of my web app. I access
it with
InputStream dmsPropsIn =
servletContext.getResourceAsStream("/WEB-INF/dms.properties");
(servletContext is a variable initialised inside my servlet's
init(): ServletContext servletContext = getServletContext();)
I don't know whether this works with JSP.
Your classes directory isn't below WEB-INF. I think it should be
there. Make sure WEB-INF is in capital letters. In case your
config is working, put /classes before the properties file name.
I think pathToTomcat/webapps/tomcat-docs/appdev/index.html is a
good starting point if you're new to servlets and web app
development.
Hope that helps
Andreas
On 4 Oct 2002 at 9:29, Troels Rossing wrote:
> Hi
>
>
>
> I am new to Slide and Servlets/JSP.
>
>
>
> I have created a taglib with a tag Message which reads a properties
> file.
>
>
>
> But I can't get access to my properties file.
>
>
>
> I deploy the app. In a war file and the structure is as follows.
>
>
>
> myApp
>
> - myJsp
>
> - classes
>
> - myprop.properties
>
> - Message.class
>
> - web-inf
>
> - mylib.tld
>
> - web.xml
>
>
>
> My only problem is the file access for myprop, everything else works
> fine, I use the following to access the file.
>
>
>
> InputStream thefile =
> this.getClass().getResourceAsStream("/myprop.properties");
>
>
>
> I have tried almost any combination of paths (the above is just one of
> them), and the only time I got it to works was when I copied the
> properties file to the shared/classes dir of the tomcat server and when
> I used the absolute path.
>
>
>
> What is the relative root dir to my application, when I deploy the war.
>
>
>
>
>
> Hope someone can help on this issue.
>
>
>
>
>
> Regards
>
>
>
> Troels
>
>
>
> www.Qualiware.com
>
>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>