You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by nformosa <nf...@gmail.com> on 2007/06/18 16:46:19 UTC

Tomcat / WAR File; Classpath not recognised for properties file

Hi All,

I'm having trouble when deploying my WAR application. The War file contains
mainly the WEB.xml, and index.html file and a number of required libraries,
incudling the compiled src code i've written, All libraries are stored
within the WEB-INF/libs which is correct. Along the libraries i have a
folder called resources, which have a number of files used as properties
files. 

The problem is that when i'm trying to access these files (property files)
i'm givin a 'Not found' error, and mainly this is due to the fact that its
looking in the bin folder of tomcat as its classpath! 

I'm accesing these files using relative paths ie: /resources/config.xml

How can i fix this problem? any ideas would really be appreciated!

thanks in advance
Nick
-- 
View this message in context: http://www.nabble.com/Tomcat---WAR-File--Classpath-not-recognised-for-properties-file-tf3940737.html#a11177124
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by 吴熊敏 <xw...@ublearning.com>.
The program's default classpath is app/WEB-INF/classes

so,you need to put the property files under this folder.

That means that when you developping,you should put property files under
the src folder.

On Mon, 18 Jun 2007 07:46:19 -0700 (PDT)
nformosa <nf...@gmail.com> wrote:

> 
> Hi All,
> 
> I'm having trouble when deploying my WAR application. The War file contains
> mainly the WEB.xml, and index.html file and a number of required libraries,
> incudling the compiled src code i've written, All libraries are stored
> within the WEB-INF/libs which is correct. Along the libraries i have a
> folder called resources, which have a number of files used as properties
> files. 
> 
> The problem is that when i'm trying to access these files (property files)
> i'm givin a 'Not found' error, and mainly this is due to the fact that its
> looking in the bin folder of tomcat as its classpath! 
> 
> I'm accesing these files using relative paths ie: /resources/config.xml
> 
> How can i fix this problem? any ideas would really be appreciated!
> 
> thanks in advance
> Nick
> -- 
> View this message in context: http://www.nabble.com/Tomcat---WAR-File--Classpath-not-recognised-for-properties-file-tf3940737.html#a11177124
> Sent from the Tomcat - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org

----------------------------
吴熊敏 <xw...@ublearning.com>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Tomcat / WAR File; Classpath not recognised for properties file

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: nformosa [mailto:nformosa@gmail.com] 
> Subject: Re: Tomcat / WAR File; Classpath not recognised for 
> properties file
> 
> Though i'm still having trouble..since the file is being 
> accessed from a class not the servlet

What does that mean (servlets are classes, after all)?  What class, and
where is it being loaded from?  What is its function if it's not part of
handling a request?

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by David Smith <dn...@cornell.edu>.
Martin --

The only exception mentioned so far is an NPE.  Nothing has indicated a 
SecurityException.

--David

Martin Gainty wrote:

> yes..All of this should work
> it sounds as if perhaps someone has been changing the security 
> permissions without your knowledge?
>
> try wrapping each executable statement with try/catch
> try {
> this.getClass().getClassLoader().getResource("resources/myfile.xml").getPath().toString()); 
>
> }
> catch(SecurityException se)
> {
>  System.out.println("A SecurityException has been thrown..please check 
> /conf/catalina.policy file the specific message="+se.getMessage());
> }
>
> Anyone?
> M--
> This email message and any files transmitted with it contain confidential
> information intended only for the person(s) to whom this email message is
> addressed.  If you have received this email message in error, please 
> notify
> the sender immediately by telephone or email and destroy the original
> message without making a copy.  Thank you.
>
> ----- Original Message ----- From: "Caldarale, Charles R" 
> <Ch...@unisys.com>
> To: "Tomcat Users List" <us...@tomcat.apache.org>
> Sent: Monday, June 18, 2007 11:46 AM
> Subject: RE: Tomcat / WAR File; Classpath not recognised for 
> properties file
>
>
>> From: nformosa [mailto:nformosa@gmail.com]
>> Subject: Re: Tomcat / WAR File; Classpath not recognised for
>> properties file
>>
>> I didn't compile the resources with the jar file! should i?
>
>
> You don't compiler resources, but the properties file can be placed in
> the jar.
>
>> if so how would i then access it?
>
>
> As previously described.
>
>> Also i don;t have a classes directory since my code is
>> compiled and jarred and forms part of the WEB-INF/lib
>
>
> Just put the properties file in base directory of the jar.
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by Martin Gainty <mg...@hotmail.com>.
yes..All of this should work
it sounds as if perhaps someone has been changing the security permissions 
without your knowledge?

try wrapping each executable statement with try/catch
try {
this.getClass().getClassLoader().getResource("resources/myfile.xml").getPath().toString());
}
catch(SecurityException se)
{
  System.out.println("A SecurityException has been thrown..please check 
/conf/catalina.policy file the specific message="+se.getMessage());
}

Anyone?
M--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- 
From: "Caldarale, Charles R" <Ch...@unisys.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, June 18, 2007 11:46 AM
Subject: RE: Tomcat / WAR File; Classpath not recognised for properties file


> From: nformosa [mailto:nformosa@gmail.com]
> Subject: Re: Tomcat / WAR File; Classpath not recognised for
> properties file
>
> I didn't compile the resources with the jar file! should i?

You don't compiler resources, but the properties file can be placed in
the jar.

> if so how would i then access it?

As previously described.

> Also i don;t have a classes directory since my code is
> compiled and jarred and forms part of the WEB-INF/lib

Just put the properties file in base directory of the jar.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Tomcat / WAR File; Classpath not recognised for properties file

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: nformosa [mailto:nformosa@gmail.com] 
> Subject: Re: Tomcat / WAR File; Classpath not recognised for 
> properties file
> 
> I didn't compile the resources with the jar file! should i? 

You don't compiler resources, but the properties file can be placed in
the jar.

> if so how would i then access it?

As previously described.

> Also i don;t have a classes directory since my code is 
> compiled and jarred and forms part of the WEB-INF/lib

Just put the properties file in base directory of the jar.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by David Smith <dn...@cornell.edu>.
Then how does the resource get into the webapp??  Yes, make sure the jar 
files you generate have the resource files.  The other option is to 
create a WEB-INF/classes/resources folder with your resource files in it.

--David

nformosa wrote:

>Neither,
>
>I didn't compile the resources with the jar file! should i? 
>
>if so how would i then access it?
>
>Also i don;t have a classes directory since my code is compiled and jarred
>and forms part of the WEB-INF/lib
>
>Thanks
>
>
>David Smith-2 wrote:
>  
>
>>So where exactly is your "resources/myFile.xml"?  Is it in the 
>>WEB-INF/classes directory of your webapp or a jar file in WEB-INF/lib?  
>>Your method of access requires it be in one of those two places.
>>
>>--David
>>
>>nformosa wrote:
>>
>>    
>>
>>>David Smith-2 wrote:
>>> 
>>>
>>>      
>>>
>>>>nformosa wrote:
>>>>   
>>>>
>>>>        
>>>>
>>>>>Hi All,
>>>>>
>>>>>I'm having trouble when deploying my WAR application. The War file
>>>>>contains
>>>>>mainly the WEB.xml, and index.html file and a number of required
>>>>>libraries,
>>>>>incudling the compiled src code i've written, All libraries are stored
>>>>>within the WEB-INF/libs which is correct. Along the libraries i have a
>>>>>folder called resources, which have a number of files used as properties
>>>>>files. 
>>>>>
>>>>>The problem is that when i'm trying to access these files (property
>>>>>files)
>>>>>i'm givin a 'Not found' error, and mainly this is due to the fact that
>>>>>its
>>>>>looking in the bin folder of tomcat as its classpath! 
>>>>>
>>>>>I'm accesing these files using relative paths ie: /resources/config.xml
>>>>>
>>>>>How can i fix this problem? any ideas would really be appreciated!
>>>>>
>>>>>thanks in advance
>>>>>Nick
>>>>> 
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>What you are seeing with it referencing the bin directory is it
>>>>accessing the directory tomcat was started from.  Depending on the
>>>>script, that can be virtually anywhere in the system.
>>>>
>>>>The servlet API provides ServletContext.getResourceAsStream(
>>>>webappRelPath ) for reading files in the webapp.  If you placed the
>>>>properties files in either WEB-INF/classes or a .jar file, you should
>>>>also be able to do it with a Class.getResourceAsStream() method.
>>>>
>>>>
>>>>--David
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To start a new topic, e-mail: users@tomcat.apache.org
>>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>>
>>>>
>>>>   
>>>>
>>>>        
>>>>
>>>
>>>Hi again,
>>>
>>>Thanks for your help!
>>>
>>>Though i'm still having trouble..since the file is being accessed from a
>>>class not the servlet the ServletContext is not valid. Then i tried to
>>>      
>>>
>print
>  
>
>>>out the following:
>>>
>>>this.getClass().getClassLoader().getResource("resources/myfile.xml").getPath().toString());
>>>
>>>but still the result is : d:\tomcat\bin\resources\myfile.xml
>>>
>>>If someone can give me a clearer idea it would be great..
>>>
>>>Thanks once again
>>>
>>>Nick
>>>
>>> 
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To start a new topic, e-mail: users@tomcat.apache.org
>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>>    
>>
>
>  
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by nformosa <nf...@gmail.com>.
Neither,

I didn't compile the resources with the jar file! should i? 

if so how would i then access it?

Also i don;t have a classes directory since my code is compiled and jarred
and forms part of the WEB-INF/lib

Thanks


David Smith-2 wrote:
> 
> So where exactly is your "resources/myFile.xml"?  Is it in the 
> WEB-INF/classes directory of your webapp or a jar file in WEB-INF/lib?  
> Your method of access requires it be in one of those two places.
> 
> --David
> 
> nformosa wrote:
> 
>>
>>David Smith-2 wrote:
>>  
>>
>>>nformosa wrote:
>>>    
>>>
>>>>Hi All,
>>>>
>>>>I'm having trouble when deploying my WAR application. The War file
>>>>contains
>>>>mainly the WEB.xml, and index.html file and a number of required
>>>>libraries,
>>>>incudling the compiled src code i've written, All libraries are stored
>>>>within the WEB-INF/libs which is correct. Along the libraries i have a
>>>>folder called resources, which have a number of files used as properties
>>>>files. 
>>>>
>>>>The problem is that when i'm trying to access these files (property
>>>>files)
>>>>i'm givin a 'Not found' error, and mainly this is due to the fact that
>>>>its
>>>>looking in the bin folder of tomcat as its classpath! 
>>>>
>>>>I'm accesing these files using relative paths ie: /resources/config.xml
>>>>
>>>>How can i fix this problem? any ideas would really be appreciated!
>>>>
>>>>thanks in advance
>>>>Nick
>>>>  
>>>>      
>>>>
>>>What you are seeing with it referencing the bin directory is it
>>>accessing the directory tomcat was started from.  Depending on the
>>>script, that can be virtually anywhere in the system.
>>>
>>>The servlet API provides ServletContext.getResourceAsStream(
>>>webappRelPath ) for reading files in the webapp.  If you placed the
>>>properties files in either WEB-INF/classes or a .jar file, you should
>>>also be able to do it with a Class.getResourceAsStream() method.
>>>
>>>
>>>--David
>>>
>>>
>>>---------------------------------------------------------------------
>>>To start a new topic, e-mail: users@tomcat.apache.org
>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>>
>>>    
>>>
>>
>>
>>
>>Hi again,
>>
>>Thanks for your help!
>>
>>Though i'm still having trouble..since the file is being accessed from a
>>class not the servlet the ServletContext is not valid. Then i tried to
print
>>out the following:
>>
>>this.getClass().getClassLoader().getResource("resources/myfile.xml").getPath().toString());
>>
>>but still the result is : d:\tomcat\bin\resources\myfile.xml
>>
>>If someone can give me a clearer idea it would be great..
>>
>>Thanks once again
>>
>>Nick
>>
>>  
>>
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Tomcat---WAR-File--Classpath-not-recognised-for-properties-file-tf3940737.html#a11178320
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by David Smith <dn...@cornell.edu>.
Then I suspect your resource isn't in a place where your webapp's 
classloaders can find it.

--David

nformosa wrote:

>This gives me a null exception!
>
>
>
>
>David Smith-2 wrote:
>  
>
>>BTW,
>>
>>this.getClass().getClassLoader().getResource("resources/myfile.xml").getPath().toString());  
>>
>>
>>should work as
>>
>>this.getClass().getResource( "/resources/myfile.xml" ).getPath() ;
>>
>>No need for all the extra noise.
>>
>>--David
>>
>>
>>
>>David Smith wrote:
>>
>>
>>    
>>
>>>So where exactly is your "resources/myFile.xml"?  Is it in the 
>>>WEB-INF/classes directory of your webapp or a jar file in 
>>>WEB-INF/lib?  Your method of access requires it be in one of those two 
>>>places.
>>>
>>>--David
>>>
>>>nformosa wrote:
>>>
>>>      
>>>
>>>>David Smith-2 wrote:
>>>> 
>>>>
>>>>        
>>>>
>>>>>nformosa wrote:
>>>>>  
>>>>>
>>>>>          
>>>>>
>>>>>>Hi All,
>>>>>>
>>>>>>I'm having trouble when deploying my WAR application. The War file
>>>>>>contains
>>>>>>mainly the WEB.xml, and index.html file and a number of required
>>>>>>libraries,
>>>>>>incudling the compiled src code i've written, All libraries are stored
>>>>>>within the WEB-INF/libs which is correct. Along the libraries i have a
>>>>>>folder called resources, which have a number of files used as 
>>>>>>properties
>>>>>>files.
>>>>>>The problem is that when i'm trying to access these files (property
>>>>>>files)
>>>>>>i'm givin a 'Not found' error, and mainly this is due to the fact that
>>>>>>its
>>>>>>looking in the bin folder of tomcat as its classpath!
>>>>>>I'm accesing these files using relative paths ie: 
>>>>>>/resources/config.xml
>>>>>>
>>>>>>How can i fix this problem? any ideas would really be appreciated!
>>>>>>
>>>>>>thanks in advance
>>>>>>Nick
>>>>>> 
>>>>>>    
>>>>>>            
>>>>>>
>>>>>What you are seeing with it referencing the bin directory is it
>>>>>accessing the directory tomcat was started from.  Depending on the
>>>>>script, that can be virtually anywhere in the system.
>>>>>
>>>>>The servlet API provides ServletContext.getResourceAsStream(
>>>>>webappRelPath ) for reading files in the webapp.  If you placed the
>>>>>properties files in either WEB-INF/classes or a .jar file, you should
>>>>>also be able to do it with a Class.getResourceAsStream() method.
>>>>>
>>>>>
>>>>>--David
>>>>>
>>>>>
>>>>>---------------------------------------------------------------------
>>>>>To start a new topic, e-mail: users@tomcat.apache.org
>>>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>>>
>>>>>
>>>>>
>>>>>  
>>>>>          
>>>>>
>>>>
>>>>
>>>>Hi again,
>>>>
>>>>Thanks for your help!
>>>>
>>>>Though i'm still having trouble..since the file is being accessed from a
>>>>class not the servlet the ServletContext is not valid. Then i tried 
>>>>to print
>>>>out the following:
>>>>
>>>>this.getClass().getClassLoader().getResource("resources/myfile.xml").getPath().toString()); 
>>>>
>>>>
>>>>but still the result is : d:\tomcat\bin\resources\myfile.xml
>>>>
>>>>If someone can give me a clearer idea it would be great..
>>>>
>>>>Thanks once again
>>>>
>>>>Nick
>>>>
>>>> 
>>>>
>>>>        
>>>>
>>>---------------------------------------------------------------------
>>>To start a new topic, e-mail: users@tomcat.apache.org
>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To start a new topic, e-mail: users@tomcat.apache.org
>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>>    
>>
>
>  
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by nformosa <nf...@gmail.com>.
This gives me a null exception!




David Smith-2 wrote:
> 
> BTW,
> 
> this.getClass().getClassLoader().getResource("resources/myfile.xml").getPath().toString());  
> 
> 
> should work as
> 
> this.getClass().getResource( "/resources/myfile.xml" ).getPath() ;
> 
> No need for all the extra noise.
> 
> --David
> 
> 
> 
> David Smith wrote:
> 
> 
>> So where exactly is your "resources/myFile.xml"?  Is it in the 
>> WEB-INF/classes directory of your webapp or a jar file in 
>> WEB-INF/lib?  Your method of access requires it be in one of those two 
>> places.
>>
>> --David
>>
>> nformosa wrote:
>>
>>>
>>> David Smith-2 wrote:
>>>  
>>>
>>>> nformosa wrote:
>>>>   
>>>>
>>>>> Hi All,
>>>>>
>>>>> I'm having trouble when deploying my WAR application. The War file
>>>>> contains
>>>>> mainly the WEB.xml, and index.html file and a number of required
>>>>> libraries,
>>>>> incudling the compiled src code i've written, All libraries are stored
>>>>> within the WEB-INF/libs which is correct. Along the libraries i have a
>>>>> folder called resources, which have a number of files used as 
>>>>> properties
>>>>> files.
>>>>> The problem is that when i'm trying to access these files (property
>>>>> files)
>>>>> i'm givin a 'Not found' error, and mainly this is due to the fact that
>>>>> its
>>>>> looking in the bin folder of tomcat as its classpath!
>>>>> I'm accesing these files using relative paths ie: 
>>>>> /resources/config.xml
>>>>>
>>>>> How can i fix this problem? any ideas would really be appreciated!
>>>>>
>>>>> thanks in advance
>>>>> Nick
>>>>>  
>>>>>     
>>>>
>>>> What you are seeing with it referencing the bin directory is it
>>>> accessing the directory tomcat was started from.  Depending on the
>>>> script, that can be virtually anywhere in the system.
>>>>
>>>> The servlet API provides ServletContext.getResourceAsStream(
>>>> webappRelPath ) for reading files in the webapp.  If you placed the
>>>> properties files in either WEB-INF/classes or a .jar file, you should
>>>> also be able to do it with a Class.getResourceAsStream() method.
>>>>
>>>>
>>>> --David
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To start a new topic, e-mail: users@tomcat.apache.org
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>>
>>>>
>>>>   
>>>
>>>
>>>
>>>
>>> Hi again,
>>>
>>> Thanks for your help!
>>>
>>> Though i'm still having trouble..since the file is being accessed from a
>>> class not the servlet the ServletContext is not valid. Then i tried 
>>> to print
>>> out the following:
>>>
>>> this.getClass().getClassLoader().getResource("resources/myfile.xml").getPath().toString()); 
>>>
>>>
>>> but still the result is : d:\tomcat\bin\resources\myfile.xml
>>>
>>> If someone can give me a clearer idea it would be great..
>>>
>>> Thanks once again
>>>
>>> Nick
>>>
>>>  
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Tomcat---WAR-File--Classpath-not-recognised-for-properties-file-tf3940737.html#a11178390
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by David Smith <dn...@cornell.edu>.
BTW,

this.getClass().getClassLoader().getResource("resources/myfile.xml").getPath().toString());  


should work as

this.getClass().getResource( "/resources/myfile.xml" ).getPath() ;

No need for all the extra noise.

--David



David Smith wrote:


> So where exactly is your "resources/myFile.xml"?  Is it in the 
> WEB-INF/classes directory of your webapp or a jar file in 
> WEB-INF/lib?  Your method of access requires it be in one of those two 
> places.
>
> --David
>
> nformosa wrote:
>
>>
>> David Smith-2 wrote:
>>  
>>
>>> nformosa wrote:
>>>   
>>>
>>>> Hi All,
>>>>
>>>> I'm having trouble when deploying my WAR application. The War file
>>>> contains
>>>> mainly the WEB.xml, and index.html file and a number of required
>>>> libraries,
>>>> incudling the compiled src code i've written, All libraries are stored
>>>> within the WEB-INF/libs which is correct. Along the libraries i have a
>>>> folder called resources, which have a number of files used as 
>>>> properties
>>>> files.
>>>> The problem is that when i'm trying to access these files (property
>>>> files)
>>>> i'm givin a 'Not found' error, and mainly this is due to the fact that
>>>> its
>>>> looking in the bin folder of tomcat as its classpath!
>>>> I'm accesing these files using relative paths ie: 
>>>> /resources/config.xml
>>>>
>>>> How can i fix this problem? any ideas would really be appreciated!
>>>>
>>>> thanks in advance
>>>> Nick
>>>>  
>>>>     
>>>
>>> What you are seeing with it referencing the bin directory is it
>>> accessing the directory tomcat was started from.  Depending on the
>>> script, that can be virtually anywhere in the system.
>>>
>>> The servlet API provides ServletContext.getResourceAsStream(
>>> webappRelPath ) for reading files in the webapp.  If you placed the
>>> properties files in either WEB-INF/classes or a .jar file, you should
>>> also be able to do it with a Class.getResourceAsStream() method.
>>>
>>>
>>> --David
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To start a new topic, e-mail: users@tomcat.apache.org
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>>
>>>   
>>
>>
>>
>>
>> Hi again,
>>
>> Thanks for your help!
>>
>> Though i'm still having trouble..since the file is being accessed from a
>> class not the servlet the ServletContext is not valid. Then i tried 
>> to print
>> out the following:
>>
>> this.getClass().getClassLoader().getResource("resources/myfile.xml").getPath().toString()); 
>>
>>
>> but still the result is : d:\tomcat\bin\resources\myfile.xml
>>
>> If someone can give me a clearer idea it would be great..
>>
>> Thanks once again
>>
>> Nick
>>
>>  
>>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by David Smith <dn...@cornell.edu>.
So where exactly is your "resources/myFile.xml"?  Is it in the 
WEB-INF/classes directory of your webapp or a jar file in WEB-INF/lib?  
Your method of access requires it be in one of those two places.

--David

nformosa wrote:

>
>David Smith-2 wrote:
>  
>
>>nformosa wrote:
>>    
>>
>>>Hi All,
>>>
>>>I'm having trouble when deploying my WAR application. The War file
>>>contains
>>>mainly the WEB.xml, and index.html file and a number of required
>>>libraries,
>>>incudling the compiled src code i've written, All libraries are stored
>>>within the WEB-INF/libs which is correct. Along the libraries i have a
>>>folder called resources, which have a number of files used as properties
>>>files. 
>>>
>>>The problem is that when i'm trying to access these files (property
>>>files)
>>>i'm givin a 'Not found' error, and mainly this is due to the fact that
>>>its
>>>looking in the bin folder of tomcat as its classpath! 
>>>
>>>I'm accesing these files using relative paths ie: /resources/config.xml
>>>
>>>How can i fix this problem? any ideas would really be appreciated!
>>>
>>>thanks in advance
>>>Nick
>>>  
>>>      
>>>
>>What you are seeing with it referencing the bin directory is it
>>accessing the directory tomcat was started from.  Depending on the
>>script, that can be virtually anywhere in the system.
>>
>>The servlet API provides ServletContext.getResourceAsStream(
>>webappRelPath ) for reading files in the webapp.  If you placed the
>>properties files in either WEB-INF/classes or a .jar file, you should
>>also be able to do it with a Class.getResourceAsStream() method.
>>
>>
>>--David
>>
>>
>>---------------------------------------------------------------------
>>To start a new topic, e-mail: users@tomcat.apache.org
>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>>    
>>
>
>
>
>Hi again,
>
>Thanks for your help!
>
>Though i'm still having trouble..since the file is being accessed from a
>class not the servlet the ServletContext is not valid. Then i tried to print
>out the following:
>
>this.getClass().getClassLoader().getResource("resources/myfile.xml").getPath().toString());
>
>but still the result is : d:\tomcat\bin\resources\myfile.xml
>
>If someone can give me a clearer idea it would be great..
>
>Thanks once again
>
>Nick
>
>  
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by nformosa <nf...@gmail.com>.


David Smith-2 wrote:
> 
> nformosa wrote:
>> Hi All,
>>
>> I'm having trouble when deploying my WAR application. The War file
>> contains
>> mainly the WEB.xml, and index.html file and a number of required
>> libraries,
>> incudling the compiled src code i've written, All libraries are stored
>> within the WEB-INF/libs which is correct. Along the libraries i have a
>> folder called resources, which have a number of files used as properties
>> files. 
>>
>> The problem is that when i'm trying to access these files (property
>> files)
>> i'm givin a 'Not found' error, and mainly this is due to the fact that
>> its
>> looking in the bin folder of tomcat as its classpath! 
>>
>> I'm accesing these files using relative paths ie: /resources/config.xml
>>
>> How can i fix this problem? any ideas would really be appreciated!
>>
>> thanks in advance
>> Nick
>>   
> What you are seeing with it referencing the bin directory is it
> accessing the directory tomcat was started from.  Depending on the
> script, that can be virtually anywhere in the system.
> 
> The servlet API provides ServletContext.getResourceAsStream(
> webappRelPath ) for reading files in the webapp.  If you placed the
> properties files in either WEB-INF/classes or a .jar file, you should
> also be able to do it with a Class.getResourceAsStream() method.
> 
> 
> --David
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 



Hi again,

Thanks for your help!

Though i'm still having trouble..since the file is being accessed from a
class not the servlet the ServletContext is not valid. Then i tried to print
out the following:

this.getClass().getClassLoader().getResource("resources/myfile.xml").getPath().toString());

but still the result is : d:\tomcat\bin\resources\myfile.xml

If someone can give me a clearer idea it would be great..

Thanks once again

Nick

-- 
View this message in context: http://www.nabble.com/Tomcat---WAR-File--Classpath-not-recognised-for-properties-file-tf3940737.html#a11178003
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by David Smith <dn...@cornell.edu>.
nformosa wrote:
> Hi All,
>
> I'm having trouble when deploying my WAR application. The War file contains
> mainly the WEB.xml, and index.html file and a number of required libraries,
> incudling the compiled src code i've written, All libraries are stored
> within the WEB-INF/libs which is correct. Along the libraries i have a
> folder called resources, which have a number of files used as properties
> files. 
>
> The problem is that when i'm trying to access these files (property files)
> i'm givin a 'Not found' error, and mainly this is due to the fact that its
> looking in the bin folder of tomcat as its classpath! 
>
> I'm accesing these files using relative paths ie: /resources/config.xml
>
> How can i fix this problem? any ideas would really be appreciated!
>
> thanks in advance
> Nick
>   
What you are seeing with it referencing the bin directory is it
accessing the directory tomcat was started from.  Depending on the
script, that can be virtually anywhere in the system.

The servlet API provides ServletContext.getResourceAsStream(
webappRelPath ) for reading files in the webapp.  If you placed the
properties files in either WEB-INF/classes or a .jar file, you should
also be able to do it with a Class.getResourceAsStream() method.


--David


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Tomcat / WAR File; Classpath not recognised for properties file

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: nformosa [mailto:nformosa@gmail.com] 
> Subject: Tomcat / WAR File; Classpath not recognised for 
> properties file
> 
> How can i fix this problem? any ideas would really be appreciated!

It's in the FAQ:
http://wiki.apache.org/tomcat/HowTo#head-45c3314139cb900ddd43dde2ff67153
2e6e844bc

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by David Smith <dn...@cornell.edu>.
Ooops... my fault.  I was thinking of getRealPath().

thanks


Caldarale, Charles R wrote:

>>From: David Smith [mailto:dns4@cornell.edu] 
>>Subject: Re: Tomcat / WAR File; Classpath not recognised for 
>>properties file
>>
>>The only achilles heal [sic] here is the
>>ServletContext.getResource() method won't work
>>from a .war archive.  The webapp has to be an
>>expanded folder.
>>    
>>
>
>Not according to the API doc:
>
>"This method allows the servlet container to make a resource available
>to servlets from any source. Resources can be located on a local or
>remote file system, in a database, or in a .war file."
>
>Note that you can also use ServletContext.getResourceAsStream() or
>Class.getResourceAsStream(), which are sometimes more convenient.
>
> - Chuck
>
>
>THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
>MATERIAL and is thus for use only by the intended recipient. If you
>received this in error, please contact the sender and delete the e-mail
>and its attachments from all computers.
>
>---------------------------------------------------------------------
>To start a new topic, e-mail: users@tomcat.apache.org
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>  
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Tomcat / WAR File; Classpath not recognised for properties file

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: David Smith [mailto:dns4@cornell.edu] 
> Subject: Re: Tomcat / WAR File; Classpath not recognised for 
> properties file
> 
> The only achilles heal [sic] here is the
> ServletContext.getResource() method won't work
> from a .war archive.  The webapp has to be an
> expanded folder.

Not according to the API doc:

"This method allows the servlet container to make a resource available
to servlets from any source. Resources can be located on a local or
remote file system, in a database, or in a .war file."

Note that you can also use ServletContext.getResourceAsStream() or
Class.getResourceAsStream(), which are sometimes more convenient.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat / WAR File; Classpath not recognised for properties file

Posted by David Smith <dn...@cornell.edu>.
If JibxManager is a class you wrote, couldn't you have the servlet 
resolve the path to resources using ServletContext.getResource( 
"/webapp-relative/path/to/my/resources" ).getPath() and then pass that 
in on the JibxManager constructor?  The only achilles heal here is the 
ServletContext.getResource() method won't work from a .war archive.  The 
webapp has to be an expanded folder.

--David

nformosa wrote:

>So, this is my layout..
>
>I've got a servlet which handles the requests. 
>
>The servlet than instantiates another class. This class called JibxManager
>(using jibx), then handles the requests and Marshals the xml request. The
>JibxManager also handles xsd verification, so it has to load the xsd. This
>xsd is one of the files i need to be loaded properly. 
>
>the xsd is accessed as follows:
>
>
>this.requestSchema = schemaFactory.newSchema(new
>File(requestSchemaLocation));
>
>where requestSchemaLocation = "resources/jibx/schema/myschema.xsd"
>
>Thanks again
>
>
>
>Peter Crowther wrote:
>  
>
>>>From: nformosa [mailto:nformosa@gmail.com] 
>>>I'm accesing these files using relative paths ie: 
>>>/resources/config.xml
>>>      
>>>
>>What code are you using to locate these files?  Hopefully something to
>>do with the servlet spec?  See, for example,
>>ServletContext.getResource(String).
>>
>>		- Peter
>>
>>---------------------------------------------------------------------
>>To start a new topic, e-mail: users@tomcat.apache.org
>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>>    
>>
>
>  
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Tomcat / WAR File; Classpath not recognised for properties file

Posted by nformosa <nf...@gmail.com>.
So, this is my layout..

I've got a servlet which handles the requests. 

The servlet than instantiates another class. This class called JibxManager
(using jibx), then handles the requests and Marshals the xml request. The
JibxManager also handles xsd verification, so it has to load the xsd. This
xsd is one of the files i need to be loaded properly. 

the xsd is accessed as follows:


this.requestSchema = schemaFactory.newSchema(new
File(requestSchemaLocation));

where requestSchemaLocation = "resources/jibx/schema/myschema.xsd"

Thanks again



Peter Crowther wrote:
> 
>> From: nformosa [mailto:nformosa@gmail.com] 
>> I'm accesing these files using relative paths ie: 
>> /resources/config.xml
> 
> What code are you using to locate these files?  Hopefully something to
> do with the servlet spec?  See, for example,
> ServletContext.getResource(String).
> 
> 		- Peter
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Tomcat---WAR-File--Classpath-not-recognised-for-properties-file-tf3940737.html#a11178377
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Tomcat / WAR File; Classpath not recognised for properties file

Posted by Peter Crowther <Pe...@melandra.com>.
> From: nformosa [mailto:nformosa@gmail.com] 
> I'm accesing these files using relative paths ie: 
> /resources/config.xml

What code are you using to locate these files?  Hopefully something to
do with the servlet spec?  See, for example,
ServletContext.getResource(String).

		- Peter

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org