Home » Language IDEs » ServerTools (WTP) » Problem locating a file in deployed WTP 2.0 Web app.
|
Re: Problem locating a file in deployed WTP 2.0 Web app. [message #211533 is a reply to message #211451] |
Wed, 02 April 2008 09:27 |
Eclipse User |
|
|
|
Originally posted by: wknauf_NO_._INSIDE_hg-online.de
Hi Milan,
I would suggest something like this (don't know wether this works in your Unit
test, as the ServletContext might not be valid, but in real life it should be fine):
String strRealPath = servletContext.getRealPath("/WEB-INF/users.properties");
PropertiesConfiguration config = new PropertiesConfiguration(strRealPath);
Best regards
Wolfgang
Milan Milanovic schrieb:
> Hi,
> I'm using Eclipse Europa + WTP 2.0 + Apache Tomcat 5.5 as a deploy
> server. My project is a "Dynamic Web Project" with "Dynamic Web Module"
> version 2.4.
>
> And I have a problem to find a path to one file located in
> "MyProject/WebContent/WEB-INF/" directory called users.properties. I'm
> trying to locate this file from a class located in "MyProject/Java
> Resources/src/somepackage" directory.
>
|
|
| |
Re: Problem locating a file in deployed WTP 2.0 Web app. [message #211650 is a reply to message #211546] |
Thu, 03 April 2008 10:13 |
Eclipse User |
|
|
|
Originally posted by: wknauf_NO_._INSIDE_hg-online.de
Probably you should store the path in e.g. some static variable in your DAO
layer. This path could either be set in the servlet (in its "init" override,
where the ServletContext is available), or from your Unit test setup method.
Hope this helps
Wolfgang
Milan Milanovic schrieb:
> Dear Wolfgang,
>
> well, I need that path in my DAO class, not in Servlet class. How my DAO
> class which is actually POJO can know for servletContext ?
>
> _____________________________
> Best regards, Milan Milanovic
>
|
|
|
Re: Problem locating a file in deployed WTP 2.0 Web app. [message #211700 is a reply to message #211650] |
Thu, 03 April 2008 13:45 |
Milan Milanovich Messages: 201 Registered: July 2009 |
Senior Member |
|
|
Hi Wolfgang,
you probably mean on absolute path ? But, how can I know path of this file
when my Web app is deployed somewhere in eclipse\workspace\.metadata\...
folder ? Later, when I deploy my application on some else Tomcat server I
must change this path. Is there any way that I link with relative path ?
__________________________
Thank you, Milan Milanovic
Wolfgang Knauf wrote:
> Probably you should store the path in e.g. some static variable in your DAO
> layer. This path could either be set in the servlet (in its "init" override,
> where the ServletContext is available), or from your Unit test setup method.
> Hope this helps
> Wolfgang
> Milan Milanovic schrieb:
>> Dear Wolfgang,
>>
>> well, I need that path in my DAO class, not in Servlet class. How my DAO
>> class which is actually POJO can know for servletContext ?
>>
>> _____________________________
>> Best regards, Milan Milanovic
>>
|
|
|
Re: Problem locating a file in deployed WTP 2.0 Web app. [message #211709 is a reply to message #211650] |
Thu, 03 April 2008 14:35 |
Milan Milanovich Messages: 201 Registered: July 2009 |
Senior Member |
|
|
Dear Wolfgang,
I supose that you mean on absolute path ? But how can I know where is that
file when deployed, it somewhere in eclipse\workspace\.metadata\... And
what if I later deploy it on Tomcat which is installed somewhere else, I
will need to chage the path. Is there any way to define a relative path
from DAO class to file in web-inf ?
_____________________________________
Thank you in advance, Milan Milanovic
Wolfgang Knauf wrote:
> Probably you should store the path in e.g. some static variable in your DAO
> layer. This path could either be set in the servlet (in its "init" override,
> where the ServletContext is available), or from your Unit test setup method.
> Hope this helps
> Wolfgang
> Milan Milanovic schrieb:
>> Dear Wolfgang,
>>
>> well, I need that path in my DAO class, not in Servlet class. How my DAO
>> class which is actually POJO can know for servletContext ?
>>
>> _____________________________
>> Best regards, Milan Milanovic
>>
|
|
|
Re: Problem locating a file in deployed WTP 2.0 Web app. [message #211797 is a reply to message #211709] |
Fri, 04 April 2008 15:12 |
Milan Milanovich Messages: 201 Registered: July 2009 |
Senior Member |
|
|
Nobody has an answer to this question ? My question is actually very
simple, is there any way to have relative path from some DAO class in src
folder to some file in WEB-INF folder ?
I have one another question, in this way by using WTP 2.0 I'm deploying
web app in Eclipse using Tomcat. But if I want to deploy final application
on some other computer that have only Tomcat installed, how can I do it ?
____________________________________
Thank you in advance,Milan Milanovic
Milan Milanovic wrote:
> Dear Wolfgang,
> I supose that you mean on absolute path ? But how can I know where is that
> file when deployed, it somewhere in eclipseworkspace.metadata... And
> what if I later deploy it on Tomcat which is installed somewhere else, I
> will need to chage the path. Is there any way to define a relative path
> from DAO class to file in web-inf ?
> _____________________________________
> Thank you in advance, Milan Milanovic
> Wolfgang Knauf wrote:
>> Probably you should store the path in e.g. some static variable in your DAO
>> layer. This path could either be set in the servlet (in its "init"
override,
>> where the ServletContext is available), or from your Unit test setup method.
>> Hope this helps
>> Wolfgang
>> Milan Milanovic schrieb:
>>> Dear Wolfgang,
>>>
>>> well, I need that path in my DAO class, not in Servlet class. How my DAO
>>> class which is actually POJO can know for servletContext ?
>>>
>>> _____________________________
>>> Best regards, Milan Milanovic
>>>
|
|
|
Re: Problem locating a file in deployed WTP 2.0 Web app. [message #211805 is a reply to message #211700] |
Fri, 04 April 2008 15:23 |
Eclipse User |
|
|
|
Originally posted by: wknauf_NO_._INSIDE_hg-online.de
Hi Milan,
you can find the absolute path through the ServletContext while your servlet is
initialized (override the "init()" method). In this moment, you have set the
absolute path to the model classes where it is required.
This way, you don't have to care about the installation location.
Hope this helps
Wolfgang
Milan Milanovic schrieb:
> Hi Wolfgang,
>
> you probably mean on absolute path ? But, how can I know path of this
> file when my Web app is deployed somewhere in
> eclipse\workspace\.metadata\... folder ? Later, when I deploy my
> application on some else Tomcat server I must change this path. Is there
> any way that I link with relative path ?
>
> __________________________
> Thank you, Milan Milanovic
>
|
|
|
Goto Forum:
Current Time: Sat Sep 21 00:31:58 GMT 2024
Powered by FUDForum. Page generated in 0.04304 seconds
|