The Google Plugin for Eclipse is deprecated and will be removed in January 2018. Migrate to Cloud Tools for Eclipse and/or the GWT Eclipse Plugin as soon as possible to avoid disruption.

Working with JSNI

The Google Plugin for Eclipse adds special treatment for one particular feature of GWT: JavaScript Native Interface (JSNI).

JSNI Methods

With GWT, you can embed raw JavaScript directly into your web applications with JSNI methods. JSNI methods are declared as native Java methods and contain inline JavaScript code within a specially-formatted multi-line comment to hide it from the Java compiler. However, this means that by default, Eclipse treats JSNI method bodies as regular Java comments.

The Google plugin, however, understands JSNI methods and makes working with embedded JavaScript nearly as easy as editing your regular Java code. It provides syntax coloring and auto-indent functionality.

JSNI code

Java References from JSNI

JSNI methods often refer to fields or classes defined in your application's Java source. The plugin provides several features to make referencing Java from JSNI easier.


JSNI Java ref completion


The plugin validates Java references and alerts you when one is broken.

Note: You can change the default severity of any type of problem with Preferences > Google > Errors/Warnings.

JSNI validation

Search Integration

Java references inside JSNI are also included when you perform a Java Search.

JSNI search

Refactoring Integration

When you refactor a referenced Java class or member, the JSNI references will be updated as well.

JSNI refactoring

JSNI Method Body Auto-completion

GWT 1.5 introduced JavaScript Overlay Types, which are Java classes that act as thin wrappers around actual JavaScript objects. The plugin makes it a snap to implement overlay types, by providing code-completions for generating the most common JSNI method bodies. Just hit Ctrl-Space at the end of a JSNI instance method signature.

JSNI body completions


Google Plugin for Eclipse