Thursday, September 5, 2013

Re: fastutils jar + gwt

1.) Make sure you have library sources + classes on your classpath
2.) Create a FastUtil.gwt.xml in package "it.unimi.dsi" containing <source path="fastutil" />. You either have to put that module into your project's src folder or you have to repack the fastutil jar and adding it to the jar file.
3.) In your app.gwt.xml you should inherit the created module of the previous step: "it.unimi.dsi.FastUtil"

4.) If you still get errors then its very likely that the fastutil library uses JRE classes that GWT can not translate to JavaScript out of the box. For these classes you have to provide your own implementation that the GWT compiler is able to translate to JavaScript. To do so you have to use GWT's "super source" mechanism. Your FastUtil.gwt.xml would then also contain something like <super-source path="super" /> and in your IDE you would exclude the "super" folder from the classpath so that its not treated as a package. Inside that "super" folder you can not put existing fastutil sources (you must keep the original package structure of course) and modify them so that the GWT compiler is able to compile them to JavaScript.
For a demonstration of that mechanism you can take a look at com.google.gwt.emul.Emulation.gwt.xml from the GWT source. Thats the GWT module that uses the super source mechanism to provide alternate implementations of the JRE classes that GWT supports out of the box. For example you can find the GWT version of java.lang.Math at https://gwt.googlesource.com/gwt/+/2.5.1/user/super/com/google/gwt/emul/java/lang/Math.java and you will recognize that it uses a lot of native JavaScript calls to increase performance.


Also keep in mind that although you code Java at the end its all JavaScript. That means a library that is maybe fast in the Java/JVM world might not be that fast once that code is translated into JavaScript. So you should think twice if its worth it and maybe do some benchmarks.


-- J.

--
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