Using ImageBundle in hosted Mode with -noserver

2 views
Skip to first unread message

grassol

unread,
Feb 7, 2008, 9:26:57 AM2/7/08
to Google Web Toolkit
We are using GWT with the -noserver Option. Everything is now running
in the Weblogic Server.
For the Images i'm using the ImageBundle. Since the bundles resides in
the packages and the images in the public/images folder, we are using
the @gwt.resource with the full qualified path like the following

/**
* @gwt.resource com/xxxx/yyyy/public/images/pic1.jpg
*/
AbstractImagePrototype getPic1();

When compiling the application with the gwt compiler, everything is
generated in one directory with images as subfolder....
This is okay and works fine in an ear-file, deployed on the
server.....

Using the hosted Mode, i copy the images folder to the webroot so that
we have the following

webroot
|
images
WEB-INF
history.html
hosted.html

and so on...

And now the images are not found, cause they are referenced with the
full qualified path.

Does somebody have any hints, how i can use the ImageBundles in the
hosted Mode and in the ear?

Thanx
Oliver

Sumit Chandel

unread,
Feb 12, 2008, 6:42:46 PM2/12/08
to Google-We...@googlegroups.com
Hi Oliver,

The ImageBundle works by assembling each of the individual images referenced in the respective getPicX() and @gwt.resource com/xxxx/yyyy/public/images/picx.jpg into one image bundle. Once that bundle is generated, all you need to do is host that image file from the same path as your generated GWT JavaScript files.

The @gwt.resource notation is only relevant to the GWT compiler to know where to pick up the individual images that will be bundled into the ImageBundle. The individual images actually don't need to be hosted on the server, only the generated image bundle. As long as you package that single image bundle with your generated JavaScript files, you should not run into any problems, in hosted mode or in deployed.

If you have other images which are not part of the bundle that you would like to package differently in the EAR file, you can use the GWT.isScript() method call to determine whether you're running in hosted mode or in web mode, and then set the path for the Image accordingly.

On the point of placing the single image bundle in the same package as the generated JS files, for most developers this hasn't been an issue, but I'm curious to know whether this poses a problem for your particular use case. Is there any reason why placing the image bundle file in the same path as the generated JS files would be a problem? If there is a reason why you would be interested in being able to place the image bundle file in a separate package, let us know.

Hope that helps,
-Sumit Chandel

Phil Issler

unread,
Feb 12, 2008, 11:10:17 PM2/12/08
to Google Web Toolkit
It would be nice if a runtime flag were added to the hosted mode shell
that would let one specify the location to write generated image
bundle files. In my case, I use Eclipse WTP to host the server (using
-noserver), and getting to the generated image bundle files is a
hassle (they go under <eclipse project dir>/www/<module name>). I
really want them to be generated in <eclipse project dir>/WebContent
so that they can be served to the hosted mode browser successfully.
Note that I choose to dispense with the module name as part of the
path on the server.

Phil

On Feb 12, 6:42 pm, "Sumit Chandel" <sumitchan...@google.com> wrote:
> Hi Oliver,
>
> The ImageBundle works by assembling each of the individual images referenced
> in the respective getPicX() and
> @gwt.resourcecom/xxxx/yyyy/public/images/picx.jpg into one image
> bundle. Once that bundle
> is generated, all you need to do is host that image file from the same path
> as your generated GWT JavaScript files.
>
> The @gwt.resource notation is only relevant to the GWT compiler to know
> where to pick up the individual images that will be bundled into the
> ImageBundle. The individual images actually don't need to be hosted on the
> server, only the generated image bundle. As long as you package that single
> image bundle with your generated JavaScript files, you should not run into
> any problems, in hosted mode or in deployed.
>
> If you have other images which are not part of the bundle that you would
> like to package differently in the EAR file, you can use the GWT.isScript()
> method call to determine whether you're running in hosted mode or in web
> mode, and then set the path for the Image accordingly.
>
> On the point of placing the single image bundle in the same package as the
> generated JS files, for most developers this hasn't been an issue, but I'm
> curious to know whether this poses a problem for your particular use case.
> Is there any reason why placing the image bundle file in the same path as
> the generated JS files would be a problem? If there is a reason why you
> would be interested in being able to place the image bundle file in a
> separate package, let us know.
>
> Hope that helps,
> -Sumit Chandel
>

Sumit Chandel

unread,
Feb 19, 2008, 1:12:13 PM2/19/08
to Google-We...@googlegroups.com
Hi Phil,

There already exists a runtime flag that you can pass in to the hosted mode shell that allows you to specify the location of the generated files. The flag you're looking for is -out. If you used the applicationCreator script to generate your shell or Eclipse run configurations, then the default -out parameter value is 'www', which explains why the image bundle file as well as all your other files are being generated in the <eclipse project dir>/www/<module name> directory. You could specify the -out parameter value as WebContent to generate the files there, although it will still package them in the <module name> subfolder to prevent filename collisions.

Also, if you just want to run your application in hosted mode with the -noserver option, you'll be happy to know that you're not required to copy all of the generated files over to the custom server you're using. In fact, if you're using GWT 1.4, the only files you really need to copy are:

1) the <module>.nocache.js file
2) the host HTML page
3) the hosted.html and history.html files generated during compilation, and
4) the <md5sum>.gwt.rpc file if your application uses GWT RPC.

Once you've set that up, hosted mode will work in exactly the same way as if you were using the embedded Tomcat server. Most importantly, it will pick up code changes if you hit "refresh" in the hosted mode browser, so you can keep a tight code-test-debug cycle.


Hope that helps,
-Sumit Chandel

Phil Issler

unread,
Feb 20, 2008, 12:23:28 AM2/20/08
to Google Web Toolkit
Thanks Sumit. I'm aware of the -out flag. The very fact that it
always uses the module name as the containing directory is the issue.
I understand the need to prevent name collisions, but in my case (and
I suspect in most cases) I am only dealing with a single module at any
given time anyway (and even if I weren't, I still probably wouldn't
have any name collisions). I suppose my main point is: if the hosted
browser creates resources each time it is run, the developer should be
given complete control over the location of those resources.

I will take a fresh look at how I might structure my development setup
to incorporate your suggestions. However I remember trying to do this
in a very similar way to what you describe back when I first started
using GWT in earnest, and I couldn't get it to work.

In any event, my recent flirtations with GWT-Ext and MyGWT have made
the ImageBundle issue almost moot for me, as those libraries cannot
use ImageBundles anyway.

Thanks again!
Phil
Reply all
Reply to author
Forward
0 new messages