getResourceAsStream for iBatis in Hosted mode

45 views
Skip to first unread message

Johan Lundberg

unread,
Jan 19, 2008, 7:28:48 PM1/19/08
to Google Web Toolkit
I am trying to load a configuration file while in hosted mode but I
fail.

ServletContext sc = this.getServletConfig().getServletContext();
InputStream r = sc.getResourceAsStream("/WEB-INF/SqlMapConfig.xml");

However, r always turns out to be null.
Is this not possible to do within the tomcat servlet container shipped
with GWT?

/johan

Charlie Collins

unread,
Jan 19, 2008, 9:36:15 PM1/19/08
to Google Web Toolkit
It's possible, but you will need to put the file on the classpath of
the embedded Tomcat. If you want it in WEB-INF then that should be
"[PROJECT]/tomcat/webapps/ROOT/WEB-INF/".

Johan Lundberg

unread,
Jan 20, 2008, 5:32:46 PM1/20/08
to Google Web Toolkit
Thanks for the advice.
However, it seems that it might be a better idea to use a standard
tomcat and try to make everything work with the -noserver option. I
use maven2 with the gwt-plugin and hope that I will get this setup
working with debugging and all.

/johan

Charlie Collins

unread,
Jan 21, 2008, 10:57:24 AM1/21/08
to Google Web Toolkit
noserver can be an option too, yes.

However, noserver has it's own issues really. First, if you create a
library that involves RPC you can't "share" it without also including
instructions and depdencies and such for others to use it. Second,
RPC testing breaks down if you use GWTTestCase and you are using
noserver.

I agree it's a pain, but personally I find munging the embedded Tomcat
to be a better option.

That's one of the reasons for the GwtWebInfProcessor in GWT-Maven
which handles all of that for you. If you have a SOURCE web.xml, it
gets included in the embedded Tomcat automatically, and so do the
dependencies needed (and also, GWT service servlets get added to your
deploy time web.xml automatically as well, if they don't already
exist). Basically it lets you have ONE web.xml, your SOURCE version,
and it gets used both in hosted mode, and when you burn a WAR.

GWT-Maven also works with noserver, but in all I prefer using it with
the embedded Tomcat, because I never have to manually muck with
anything, and it all just works.

Isaac Truett

unread,
Jan 22, 2008, 12:52:30 PM1/22/08
to Google-We...@googlegroups.com
Johan,

Have you considered class.getResourceAsStream("/SqlMapConfig.xml")?
That will allow you to access resources on the classpath instead of as
URLs relative to the application context. "/SqlMapConfig.xml" would
refer to /WEB-INF/classes/SqlMapConfig.xml.

- Isaac

Reply all
Reply to author
Forward
0 new messages