You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Allen,Eva" <al...@oclc.org> on 2006/10/31 21:15:44 UTC

getSystemResource not working in servlet

I'm still having problems with getting xmlrules to work within a Tomcat
servlet container.  I pretty much snagged the code I use from the
xmlrules example that comes with the digester source.  The problem comes
with the getSystemResource call.  I keep getting a null URL.  I finally
named the rules file x.xml and placed it in every directory under
$TOMCAT_HOME and used the following code:
            
URL rulesURL = ClassLoader.getSystemResource("x.xml");

but still the returned URL is null.  This works fine as long as I'm not
running within the Tomcat servlet container.  It also works fine if I do
this instead

            URL rulesURL = null;
            File f = new File("x.xml");
            try {
                rulesURL = f.toURL();
            } catch (MalformedURLException e1) {
                e1.printStackTrace();
            }

but I'd much prefer to do it the "right" way if I could.  Any hints?

--
Eva Allen
Consulting Software Engineer, OCLC, Inc.
6565 Frantz Rd., Dublin, OH  43017
614.764.6009 | allene@oclc.org
Views contained herein are my own; they do not necessarily reflect those
of my employer


---------------------------------------------------------------------
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: getSystemResource not working in servlet

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Allen,Eva [mailto:allene@oclc.org] 
> Subject: getSystemResource not working in servlet
> 
> URL rulesURL = ClassLoader.getSystemResource("x.xml");

This only retrieves resources accessible to the System class loader,
which typically only looks at the $TOMCAT_HOME/bin directory.

> but I'd much prefer to do it the "right" way if I could.  Any hints?

>From within a webapp, you would normally use getResourceAsStream().
Take a look at 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