First off, if you have such methods, then your object is not just a DTO (by definition, a DTO only has accessors and mutators).
That being said, there are several ways to solve your problem with your objects.
- to solve the
NoClassDefFoundError
, usecom.google.gwt.core.shared.GWT
instead ofcom.google.gwt.core.client.GWT
. The shared class is present in bothgwt-user.jar
andgwt-servlet.jar
. - You can use
GWT.isClient()
to tell whether you're on the client-side or server-side and branch to the appropriate code. - Starting with GWT 2.6,
GWT.create()
can be used outside of a GWT client-side context, so you can make it work on the server-side (you have to provide your ownClassInstantiator
tocom.google.gwt.core.server.ServerGwtBridge.getInstance()#register()
) - If you have a server-side-specific method that wouldn't even transpile to JavaScript, starting with GWT 2.6, you can annotate it with
@GwtIncompatible
(any such annotation will work, the package doesn't matter, only the annotation name) and GWT will do as if it isn't there at all. - finally, when none of the above works, you can "fork" your code into a
super-source
, so as to provide distinct server-specific and client-specific implementations. See “Overriding one package implementation with another” in the GWT documentation.