I've never used getResourceAsStream() from a class loader.

The one thing I can point out is that by specification, the ServletContext.getResourceAsStream() requires that the file name start with /. If you're getting Tomcat's class loader that would explain the problem.



Jacob Bergöö wrote:
Hi,
my code looks like this:


                    ...
                    final Resource resource = iterator.next();
                    final Context cx =
ContextFactory.getGlobal().enterContext();
                    final StringBuilder stringBuilder = new StringBuilder();

                    final String resourcePath = resource.getURI().getPath();
                    logger.debug("Trying to load resource {}",
resourcePath);
                    try {
                        final InputStream resourceStream =
this.getClass().getClassLoader().getResourceAsStream(resourcePath);
                        if (resourceStream == null) {
                            throw new RuntimeException("Failed to get
resource as stream: " + resourcePath);
                        }
                        final BufferedReader br = new BufferedReader(new
InputStreamReader(resourceStream));
                        String line;
                        while ((line = br.readLine()) != null) {
                            stringBuilder.append(line).append("\n");
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    ...


and in springs application context file:

<bean id="dwtHelper" class="com.mycompany.DWTHelper" init-method="init" >
        <property name="javascriptResourceList">
                <list>
                        <value>file:/configure.js</value>
                        <value>file:/dojo.js.uncompressed.js</value>
                        <value>file:/dwt.js.uncompressed.js</value>
                        <value>file:/template_dwt_parser.js</value>
                </list>
        </property>
</bean>

thanks for taking time to help,
Jacob



George Sexton wrote:
Are you using getResourceAsStream()? Do your paths start with / ?

Jacob Bergöö wrote:
Hi All,
I have a problem when I deploy my war file on Tomcat 6.0.18 that does not
occur when I deploy the same war file on my Jetty web server.

My war file contains a jar artifact that when Spring is initialized reads
a
couple of js files and process them using Rhino on the server side. This
works fine when I develop it because I am using Jetty when I run it local
on
my machine, but when I try to run it on our development server that runs
a
Tomcat then It suddenly does not work.
In What way are Tomcat treating this resources differently than Jetty?
What
do I need to do to fix this?

Thanks for any suggestions,

Jacob
--
George Sexton
MH Software, Inc.
Voice: +1 303 438 9585
URL:   http://www.mhsoftware.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org





--
George Sexton
MH Software, Inc.
Voice: +1 303 438 9585
URL:   http://www.mhsoftware.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to