fastutils jar + gwt

503 views
Skip to first unread message

rex

unread,
Sep 5, 2013, 1:03:43 PM9/5/13
to google-we...@googlegroups.com
Maybe there is a documentation somewhere  that I am missing but I am having a hard time linking external project modules to my gwt application. If someone can just elaborate how to link an external project like apache commons or something else to gwt, that would really help


I have been trying to integrate fastutils from http://fastutil.di.unimi.it/ for some time now to my gwt project. I have already updated my gwt.xml file with:

<inherits name="it.unimi.dsi.fastutil" />

I have also added a gwt.xml file to my jar since it doesn't have it. Here are the contents of my added file:

 <module>
  <inherits name='com.google.gwt.user.User'/>
  <inherits name="com.google.gwt.xml.XML"/>
  <inherits name="com.google.gwt.i18n.I18N"/>    
  <inherits name="com.google.gwt.json.JSON"/>
  <inherits name="com.google.gwt.http.HTTP"/>
  <inherits name="com.google.gwt.event.Event"/>
  <source path='fastutil'/>
</module> 

Still, when I compile, it keeps on failing with the notoriious "no source code found for ... ..."

Any helps or recommendations in this area?

Thanks,
Rex


Jens

unread,
Sep 5, 2013, 6:35:52 PM9/5/13
to google-we...@googlegroups.com
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.

rex

unread,
Sep 9, 2013, 1:56:36 PM9/9/13
to google-we...@googlegroups.com
Thanks Jens for your previous reply. I was able to remodify my items as follows but now I get a different error:

[ERROR] Hint: Previous compiler errors may have made this type unavailable
               [ERROR] Hint: Your source appears not to live underneath a subpackage called 'client'; no problem, but you'll need to use the <source> directive in your module to make it accessible


The above tells me that it is not finding the 'fastutils' package in the same folder fine. I would have loved to create a client folder, but I dont want to mess up the fastutil structure. Any other recommendations on how to make it find the source files and make this work? Thanks. Here is my updated files and their contents:

my app.gwt.xml file.
<inherits name="it.unimi.dsi.FastUtil" /> 

inside my fastutil jar. I created the file "FastUtil.gwt.xml" file in "it.unimi.dsi" path as I had before. here are the contents

 <module>
  <source path="fastutil"/>
  <super-source path="super" /> 
  <inherits name="com.google.gwt.user.User"/>
  <inherits name="com.google.gwt.xml.XML"/>
  <inherits name="com.google.gwt.i18n.I18N"/>    
  <inherits name="com.google.gwt.json.JSON"/>
  <inherits name="com.google.gwt.http.HTTP"/>
  <inherits name="com.google.gwt.event.Event"/>
</module> 

Jens

unread,
Oct 15, 2013, 11:11:51 AM10/15/13
to google-we...@googlegroups.com
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.

Small typo correction:

"Inside that "super" folder you can now 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."

-- J.
Reply all
Reply to author
Forward
0 new messages