Monday, February 24, 2014

How to load a JRE-dependent/non-compile-mode-supported class in GWT Dev Mode

For a particular GWT module, I'm able to solve a problem in compiled mode by manipulating the JS object representing the Java object.  (Specifically, I need to clone the object, so I simply create a new JS object, copy the properties from the original JS object, and assign a new hash value.)  I've tested this an it works OK.

Since that approach (that I use in compiled mode) doesn't work in Dev Mode, I want to use Object.clone(), which is available in Dev Mode, to perform the clone operation. However, I'm not sure how to accomplish this as every approach I try hits a problem.
  • I can't seem to use deferred binding (i.e. GWT.create() and "replace with" in the module gwt.xml file), for two reasons:
    1. Even in Dev Mode, when I replace a class using "replace with", the class I swap in seems not to be able to use JRE-only methods, such as reflection or Object.clone.  I get an error that the "source code for the method is not available".  I don't want this class compiled, but it seems to want to compile it to JS.
    2. If I solve #1, then I have to figure out how to get the "replace with" to be conditional based on being in dev mode.  I'm using ant to build the compiled-mode stuff and I'm using Eclipse to run dev mode.  Is there way to make this automatic so I can use the same module gwt.xml in Eclipse and for an ant build?  I guess I'd need an ant property that automatically is set by compiled but not by development mode, or vice versa?
  • I also tried simply using new Foo() (rather than GWT.create() and deferred binding), placing the JS-copying/GWT-compile-friendly version of Foo in the normal location.  This works for GWT compiled mode obviously.  Then for Dev Mode, I add a new source directory to the class path in Eclipse and stick a different class Foo there that uses the JRE-only APIs (such as Object.clone).  However, this hits the same problem as deferred binding - I still get an error that "the source code is not available" for various APIs I use in that version of Foo (e.g. reflection APIs).

Right now, I've managed to use the Eclipse expression panel to manually load the JRE-version of Foo I mentioned above (in the special class path segment).  So I know it's possible for it to coexist with other Dev Mode classes, but how do I load it programmatically as part of starting GWT DevMode class?

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment