Using a common code both at client and server side

1 view
Skip to first unread message

sriram

unread,
Nov 10, 2008, 11:47:11 PM11/10/08
to Google Web Toolkit
Hi,

Do we use a common code written in java, that could be used at both
the client and server side using gwt.

for example, cache a common folder used at both the ends.

Thanks,
Sriram

Jason Essington

unread,
Nov 11, 2008, 3:04:56 PM11/11/08
to Google-We...@googlegroups.com
sure, and in fact it is quite common to use the same code in both
places.

The easy way to do this is to consolidate that shared code into a
particular package ... something like com.foo.bar.shared

Then create a new GWT.xml file com/foo/bar.Shared.gwt.xml and add
<source path="shared"/>

your module containing your entry point would then add <inherits
name="com.foo.bar.Shared"/>

and your server code would just reference those classes like normal.

The trick here is to remember to only place translatable code in
com.foo.bar.shared. Since it is going to be compiled to javascript, it
will have to abide by all of the rules of client code.

-jason

sriram

unread,
Nov 12, 2008, 11:15:05 PM11/12/08
to Google Web Toolkit
Hi Jason,

Thank you very much.
Correct me if i am wrong.
Is this a similar way, to creating a module

Jason Essington

unread,
Nov 13, 2008, 11:09:08 AM11/13/08
to Google-We...@googlegroups.com
Yes, by adding a gwt.xml file, you have basically created a module,
but without an entry point defined the module cannot be compiled on
its own, only inherited by other modules.

-jason
Reply all
Reply to author
Forward
0 new messages