how to handle resources on server side (maven gwt)

78 views
Skip to first unread message

tanteanni

unread,
Jul 4, 2011, 11:35:08 AM7/4/11
to google-we...@googlegroups.com
i need some files on sever side but the normal: put it in "resources"-Folder(i created one because webappcreator didn't) and use MyClass.class.getResourceAsStream("/" + "filename"); does not work?! i allways get null. usind FileInputStream and absolute path works. gwt-maven-plugin copies the file to target but it seems that it is not part of classpath?!
what is the normal way to use resources on server side in a gwt/maven project?

thx in advance

Hilco Wijbenga

unread,
Jul 4, 2011, 1:18:33 PM7/4/11
to google-we...@googlegroups.com

GWT is mostly client side so I doubt it has anything to do with this problem.

Server side everything Java should work normally. Is this code in a
web app (i.e. a WAR)? Or standalone? If a WAR then note the difference
between src/main/resources and src/main/webapp. Check what ends up in
your WAR and where.

Also, if a WAR, you should use
Thread.currentThread().getContextClassLoader().getResourceAsStream()
or this.getClass().getResourceAsStream(). The leading slash might be
implied, i.e. the filename is treated as being absolute (I read that
somewhere, I haven't checked whether it's true).

tanteanni

unread,
Jul 7, 2011, 2:07:47 AM7/7/11
to google-we...@googlegroups.com
thx,

the problem is this is my first web-app so it's hard for me to distinguish between gwt specific and webapp specific problems. my problem is that i never had problem with resource handling because of maven (all that is copied to resources is accassible via getClass().getResource...).
But probably the different resource handling is the reason why gwt's webappcreator don't generate resource-folder?!

tanteanni

unread,
Jul 7, 2011, 3:24:29 AM7/7/11
to google-we...@googlegroups.com
in meantime i tried to put my file to main/webapp/WEB-INF/myfile (next to web.xml). but getResurceAsStream("/"+myfile) still returns null (with or without "/"). so where to copy resources to? (i don't want to manipulate the pom)

Marius Grama

unread,
Jul 7, 2011, 3:55:19 AM7/7/11
to Google Web Toolkit
Hi,

put your resource to be retrieved via
Thread.currentThread().getContextClassLoader().getResourceAsStream()
in src/main/java or src/main/resources on your IDE so that it can be
exported to WEB-INF/classes (instead of just WEB-INF/ directory).
Reply all
Reply to author
Forward
0 new messages