Hi Henri, nice to see you there ;-)
On 29 mai, 14:19, hsivonen <
hsivo...@gmail.com> wrote:
> I'd like to compile a rather complex Java library that I've written
> into a JavaScript library that would expose a single JavaScript
> function entry point in the global scope. Something like
> public static void parseHtml5(String source, JavaScriptObject
> nativeDomDocument)
> exposed as window.parseHtml5(source, nativeDomDocument)
>
> How do I set up Java-to-JavaScript compilation under Eclipse in such a
> way that the output is just a single .js file which upon inclusion
> adds an entry point function to the window object? I don't want a full
> GWT app.
To compile to JS and have some code running "at loading time" (to
export your parseHtml5 function), you need to make a GWT
"application" (your need an EntryPoint). Note however that a GWT app
doesn't have to have any UI at all (you're not forced to include the
com.google.gwt.user.User module if you don't want to), it's just JS
after all...
> I need to include classes whose package name doesn't end with
> ".client".
Put a <source path="..." /> in your "HTMLParser.gwt.xml" module
description file.
> Also, I have some SAX dependencies, so I need to provide a
> non-JDK version of a subset of SAX to the JS compilation, but I don't
> want that to interfere with normal Java compilation.
The "common practice" is to place your code in a "super" directory,
sibling of your "src" dir, and put a <super-source path="..." /> in
your module.
The super/* won't be a "source folder" in your Eclipse project so it
won't interfere with "normal Java compilation", but you'll add to the
classpath when running the GWTCompiler.
See
http://code.google.com/p/bunsenandbeaker/wiki/DevGuideModuleXml
for info about <super-source/>, and have a look at GWT's user/ source.
> More concretely, I now have
> nu.validator.htmlparser.common (needs to be included in JS)
> nu.validator.htmlparser.impl (needs to be included in JS)
> nu.validator.htmlparser.(various) (other packages that should be
> omitted from JS compilation)
> under src/ in my Eclipse project.
>
> I'd like to be able to just add nu.validator.htmlparser.gwt with the
> GWT specific classes (including JSNI stuff) under e.g. gwt-src/ (so
> that it is easy to omit in Mavenized .jar export) and org.xml.sax with
> copies of the part of SAX interfaces and exceptions that the JS
> compiler needs to see someplace where it doesn't trip up normal Java
> operation.
I'd place the HTMLParser.gwt.xml in nu.validator.htmlparser and use:
<source path="common" />
<source path="impl" />
<source path="gwt" />
Another solution is to have a Common.gwt.xml in
nu.validator.htmlparser.common and an Impl.gwt.xml in
nu.validator.htmlparser.impl, and <inherits/> them from your
HTMLParser.gwt.xml residing in nu.validator.htmlparser.gwt.
Those are just two example layouts among others...