Fork me on GitHub

Screen Shot 2016-05-25 at 20.53.42

In this page, we step through the creation of a JSweet program in Eclipse, using the JSweet Eclipse plugin (see also on Github).

Note: under Eclipse, you can also use the excellent SDBG plugin to debug your JSweet application with the debug perspective.


  • Under Eclipse, go to: Help > Install New Software.
  • Press the “Add…” button to add the update site.
  • Update site URL

  • Follow the installation instructions (keep the default options) and restart Eclipse when prompted.

How to start from the quick start project

  • Clone the jsweet-quickstart project from Github and import it to your workspace
  • Right click on your newly added project: Properties > JSweet > Enable project specific settings. Set the generated JavaScript folder to target/js
  • Right click on your newly added project: Configure > Enable JSweet builder.
  • Clean the project: the target/js should be populated.
  • Right-click on webapp/index.html and choose Open with > System editor. If successful, your browser should popup an alert.
  • Read the following sections to get some hints on how to write JSweet code.

How to start from a blank project

Create and configure the project

  • Create a new Java project: File > New > Java Project.
  • Name it “jsweet-tutorial” (for instance). Press the “Finish” button to keep the default settings.
  • Right click on your newly added project: Configure > Enable JSweet builder.
  • Right click on  your project: Configure > Convert to Maven Project. Leave all the default options.
  • Edit your pom.xml to add the JSweet repository. Note that this step will not be mandatory in the future, when JSweet will be available in Maven Central.
  • <project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
      <!-- repositories -->
          <snapshots />
      <!-- end repositories -->
  • In the dependencies section of the pom.xml (at the root of your Java project), add a dependency to the core JSweet library (a.k.a. candy). This will add the JSweet core APIs to your classpath.
  • <project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
      <!-- dependencies -->
        <!-- JSweet core API -->
      <!-- end dependencies -->
  • When saving your POM, you should now see the “Maven Dependencies” node added to your project. If so, you are all set to start programming 🙂

Write your first program

  • Right-click on the src folder of your project and choose: New > Class.
  • As shown in the following screenshot, create a HelloWorld Java class in a helloworld package. Check the “create main method” option.
  • In the main method, type in al and press CTRL+SPACE. If correctly configured, the alert method of jsweet.dom.Globals should be proposed by the auto-completion (JSweet adds some favorites static members automatically, so that you will get completion on globals such as alert() or document, as shown in the screenshot below).
  • tuto_alert-autocompletion

  • Now, with the help of completion, write the following JSweet program, which will set the content of a div to “Hello world!” with first warning the user.
  • package helloworld;
    import static jsweet.dom.Globals.*;
    import jsweet.dom.HTMLElement;
    public class Globals {
    	public static void main(String[] args) {
    		alert("This example writes 'Hello world' in the document!");
    		HTMLElement e = document.getElementById("target");
    		e.innerHTML = "Hello world!";
  • When this program compiles and is saved, check your project for the js directory at the root of the project. You should find the generated JavaScript file at /js/helloworld/HelloWorld.js.
  • Then, create an index.html file in the helloworld package, next to the HelloWorld class. We recommend that you use version of Eclipse for Web developers, or that you install the Web Developer Tools plugin available at the Eclipse’s market place.
  • <!DOCTYPE html>
    <meta charset="UTF-8">
    <title>Hello world</title>
        <div id="target"></div>
        <script type="text/javascript" src="../../js/helloworld/HelloWorld.js"></script>
  • Finally, open this HTML page in your favorite Web browser: right-click on the HTML file and choose Open with > System editor. If successful, your browser should popup an alert and show “Hello world!” in the page.
  • If this went well, congratulations! You can now play with more complex examples. You can also read about more details on JSweet design and how to use its APIs.
JSweet is looking for a new maintainer/owner! If interested, please contact us at details...