- Typically, J4TS can be used as a runtime for transpilers, so that you can use the Java APIs in your transpiled Java programs. So far, J4TS main target is theJSweet transpiler, but it is not limited to it.
J4TS currently covers most of the core Java API supported by GWT (
java.util , some
java.io ). It does not support
java.math yet because the GWT implementation requires a deep Java emulation, which is not consistent with the JSweet approach (so
java.math should be implemented as a wrapper forbignumber.js for instance).
J4TS is intended to be completed on-the-fly as more use cases are needed. So feel free to contribute.
import List = java.util.List; import ArrayList = java.util.ArrayList; import Set = java.util.Set; import HashSet = java.util.HashSet; import Map = java.util.Map; import HashMap = java.util.HashMap; var l: List<String> = new ArrayList<String>(); l.add("a"); l.add("b"); l.add("c"); assertEquals("[a, b, c]", l.toString()); assertEquals(l.indexOf("a"), 0); var s: Set<String> = new HashSet<String>(); s.add("a"); s.add("a"); s.add("b"); s.add("c"); s.add("c"); assertEquals(3, s.size()); assertTrue(s.contains("c")); var s: Map<String, String> = new HashMap<String, String>(); s.put("a", "aa"); s.put("b", "bb"); s.put("c", "cc"); assertEquals("bb", s.get("b"));
How to use
From JSweet, add the candy dependency in your
<dependency> <groupId>org.jsweet.candies</groupId> <artifactId>j4ts</artifactId> <version>0.1.0</version> </dependency>
A simple and still incomplete test suite is availablethere. Make sure that the tests pass by openingindex.html.
How to build
Use Gulp to clean temporary files (required: Gulp and required modules).
> gulp clean
target directory (required: JSweet ).
> mvn clean generate-sources
To build and install the JSweet candy in your local Maven repository.
> gulp prepare-jsweet-candy > cd packaging/jsweet-candy > mvn clean install
J4TS is meant to serve the public interest and be as open as possible. So anyone is more than welcome to contribute as long as it does not deviate J4TS from its initial goals stated above. When you meet a class or a method that is not supported, please feel free to contribute under the terms of the license.
J4TS is licensed under the Apache Open Source License version 2.