GWT Exclude Package From Source Path

Problem

The Google Web Toolkit Java to JavaScript transpiler is a powerful tool to convert Java source code into JavaScript files. Unfortunately, not all Java code can be transpiled into JavaScript code by GWT.

Sometimes, a project contains a mix of Java code that can be converted into JavaScript and Java code that doesn’t. In that case, the GWT compiler issues errors such as ‘No source code is available for type …‘.

Solution

GWT module definitions (.gwt.xml) files allow to specify fine-grained rules which files in a project are to be converted and which files should not. The rules are based on Ant patterns, which can be difficult to wrap one’s head around. Below are a few handy examples.

Exclude all files in packages with the name ‘/jre/’

<source path='' >

    <exclude name="**/jre/**" />
</source>

Exclude the file ‘ForJre.java’:

<source path='' >
   <exclude name="**/ForJre.java" />
</source>

Google Releases Tool J2ObjC to convert Java Source Code into Objective-C Source Code

I love the Google Web Toolkit, a powerful and mature open source library to automatically translate Java Source Code into JavaScript code. While I doubt the merit of using Java to write user interfaces for JavaScript (unfortunately, this is often what the Google Web Toolkit has been advocated for), I think it is a great tool to share Business Logic between Java and JavaScript applications.

In this context, I am very happy to see Google release the free tool J2ObjC: This library is targeted to translate Java Business Logic code (not UI code!!!) from the Java Source Code into Objective-C source code. The objective of this project really appears to be to share libraries between Java and iOS applications rather than translating entire applications (with UI) from Java into Objective-C: a limitation I think is a great strength!

I hope that soon we will be able to write Business Logic-level code just once and then embed it everywhere!!!