Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » Problem locating a file in deployed WTP 2.0 Web app.
Problem locating a file in deployed WTP 2.0 Web app. [message #211451] Tue, 01 April 2008 16:27 Go to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
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. So, in my com.myapp.package.MyClass
I have following line:

--
PropertiesConfiguration config = new
PropertiesConfiguration("WebContent/WEB-INF/users.properties ");
--

and this works if I run JUnit test of this class, but when I deploy
application to a Apache Tomcat using "Run As->Run on Server..." I got an
FileNotFoundException.

So, to sum up my question, how can I have a unique path to some file from
my source classes, if that file is located in WEB-INF directory ?

I should note that the file users.properties must be located in WEB-INF
directory, because Acegi Security library search for it there.

Thank you in advance.

--
Milan Milanovic
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #211546 is a reply to message #211533] Wed, 02 April 2008 13:26 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
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

Wolfgang Knauf wrote:

> 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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
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 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
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 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
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 Go to previous message
Eclipse UserFriend
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
>
Previous Topic:MalformedInputException on tag files
Next Topic:Parse HTML file
Goto Forum:
  


Current Time: Thu Dec 18 04:11:06 GMT 2014

Powered by FUDForum. Page generated in 0.10738 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software