ServletContext.getResourceAsStream():
http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/ServletContex
t.html#getResourceAsStream(java.lang.String)
(I believe it shows up starting in JSDK version 2.1, or Tomcat 3.2.)
-- Bill K.
> -----Original Message-----
> From: Pedro Salazar [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, June 26, 2001 6:24 AM
> To: [EMAIL PROTECTED]
> Subject: open xml/xsl files inside classpath
>
>
> Greetings,
>
> I have a servlet which read some properties (using the
> ResourceBundle)
> from a properties file in a package PT.teste.props where exists a
> relation like this:
>
> "
> fileA.xml = file1.xsl
> fileB.xml = file2.xsl
> ...
> "
>
> Of course getting the properties file is simple task because
> I just use
> the location in classpath, ex:
>
> rb=ResourceBundle.getBundle("PT.teste.props."+properties_file);
>
> But, now I would like to open both files, the xml and the xsl file,
> which are in a package PT.teste.xml. I tested using the
> absolute path to
> them, but is not very recommendable because tomorrow I
> probably will put
> it in another location or in another machine...
>
> "
> Source xmlSource = new javax.xml.transform.stream.StreamSource (new
> java.net.URL("file:///opt/jakarta-tomcat-3.2.1/webapps/servlet
> _teste/WEB-INF/classes/PT/teste/xml/fileA.xml").openStream());
> Source xslSource = new javax.xml.transform.stream.StreamSource (new
> java.net.URL("file:///opt/jakarta-tomcat-3.2.1/webapps/servlet
> _teste/WEB-INF/classes/PT/teste/xml/file1.xsl").openStream());
> "
>
> Is there a easy way to open a file in a classpath directly?
> Or at least
> a way where the path is relative to the web application? A not very
> recommendable way just to solve my problem is use a path in a
> properties
> file which I would read in the init() of servlet... but, I
> wouldn't like
> to do it!
>
> thanks,
> Pedro Salazar.
>