ikarienator / jsweet

A Java to JavaScript transpiler.

Home Page:http://www.jsweet.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSweet: a Java to JavaScript transpiler Build Status

JSweet is built on the top of TypeScript to bring the most up-to-date JavaScript APIs right to the Java world. JSweet can be seen as a Java syntax layer to TypeScript.

JSweet is not Java, it is Java syntax only. JavaScript APIs and core objects are all accessible. Java APIs are accessible with some limitations, either through compile-time mapping to TypeScript APIs, either using the J4TS candy, which provides an implementation of the core Java APIs in JSweet.

JSweet programs usually run on a JavaScript VM, but the programs that only use Java APIs can also run on a Java VM. So you are able to share some code between Java and JavaScript. With JSweet, you take advantage of all the Java tooling to program real JavaScript applications using the latest JavaScript libraries. JSweet is designed to be as safe as possible and generate fully type-checked JavaScript programs.

Features

  • Full syntax mapping between Java and TypeScript, including classes, interfaces, functional types, union types, tuple types, object types, string types, and so on.
  • Extensive support of Java constructs and semantics added since version 1.1.0 (inner classes, anonymous classes, final fields, method overloading, instanceof operator, static initializers, ...).
  • Over 1000 JavaScript libraries, frameworks and plugins to write Web and Mobile HTML5 applications (JQuery, Underscore, Angular, Backbone, Cordova, Node.js, and much more).
  • A Maven repository containing all the available libraries in Maven artifacts (a.k.a. candies).
  • Support for Java basic APIs as the J4TS candy (forked from the GWT's JRE emulation).
  • An Eclipse plugin for easy installation and use.
  • A Maven plugin to use JSweet from any other IDE or from the command line.
  • A debug mode to enable Java code debugging within your favorite browser.
  • A set of nice WEB/Mobile HTML5 examples to get started and get used to JSweet and the most common JavaScript APIs (even more examples in the Examples section).
  • Support for bundles to run the generated programs in the most simple way.
  • Support for JavaScript modules (commonjs, amd, umd). JSweet programs can run in a browser or in Node.js.
  • Support for various EcmaScript target versions (ES3 to ES6).
  • ...

For more details, go to the language specifications (PDF).

Getting started

  • Step 1: Install (or check that you have installed) Git, Node.js and Maven (commands git, node, npm and mvn should be in your path).
  • Step 2: Clone the jsweet-quickstart project from Github:
> git clone https://github.com/cincheo/jsweet-quickstart.git
  • Step 3: Run the transpiler to generate the JavaScript code:
> cd jsweet-quickstart
> mvn generate-sources
  • Step 4: Check out the result in your browser:
> firefox webapp/index.html
  • Step 5: Edit the project and start programming:
    • Checkout the examples to see various use cases
    • Refer to the language specifications to know more about programming with JSweet
    • Eclipse users: install the Eclipse plugin to get inline error reporting, build-on-save, and easy configuration UI

More info at http://www.jsweet.org.

Examples

  • Examples illustrating the use of various frameworks in Java (jQuery, Underscore, Backbone, AngularJS, Knockout). Go to project.
  • Examples illustrating the use of the Threejs framework in Java. Go to project.
  • Node.js + Socket.IO + AngularJS. Go to project.
  • Some simple examples to get started with React.js. Go to project.

Tooling

News and more information

Most information is available on the http://www.jsweet.org. Developers, check out the wiki.

How to build

Prerequisites: node and npm executables must be in the path (https://nodejs.org). Note that there seem to be an issue with the node executable on some Unix-based machines, which should be fixed (see for instance: http://askubuntu.com/questions/235655/node-js-conflicts-sbin-node-vs-usr-bin-node).

To build the jsweet-transpiler jars (in the project's directory):

> mvn package

To install the jsweet-transpiler artifact in your local Maven repository:

> mvn install

Note that current JUnit tests launch a Node.js instance for each test and will be quite slow (this will be improved). In order to easily test some changes locally without having to run all the tests, use the following command:

> mvn package -Dmaven.test.skip=true

or

> mvn install -Dmaven.test.skip=true

To generate the markdown language specifications from the Latex source file with Pandoc:

> cd doc
> pandoc -r latex -w markdown_github --base-header-level=2 -s --toc --number-sections -B header.md -o jsweet-language-specifications.md jsweet-language-specifications.tex

Note that the following command will output the document in HTML:

> pandoc -r latex -w html5 --base-header-level=3 -o jsweet-language-specifications.html jsweet-language-specifications.tex

License

JSweet is under the Apache 2.0 Open Source license.

About

A Java to JavaScript transpiler.

http://www.jsweet.org

License:Apache License 2.0


Languages

Language:Java 98.4%Language:TypeScript 0.7%Language:JavaScript 0.6%Language:HTML 0.3%