Step 2: Clone the
jsweet-quickstart project from Github
> git clone https://github.com/cincheo/jsweet-quickstart.git (for older versions only) > git checkout tagName
> 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
All you need to know about using existing candies (or creating your own) is summarized here.
When having a lot of files in a program, it is useful to create a bundle so that you don’t need to include your files one by one. Also bundling your programs will take care of the dependencies and avoid the problem of referencing a class or a variable that has not been defined yet. To enable JSweet bundling, you just need to set the
bundle option to
true in your
pom.xml. Check out the Maven plugin documentation for more information on available options.
<project ...> ... <build> ... <plugins> ... <plugin> <groupId>org.jsweet.v3</groupId> <artifactId>jsweet-maven-plugin</artifactId> <version>3.0.0</version> <configuration> <sourceMap>true</sourceMap> <outDir>target/js</outDir> <targetVersion>ES3</targetVersion> <!-- bundle your JS automatically --> <bundle>true</bundle> <!-- end of bundle configuration --> </configuration> ... </plugin> ...
Finally, you can use an external bundler, such as Browserify, to create bundles. Bundlers usually require the use of modules (for instance Browserify works with commonjs modules). See the next section to learn how to build your application with modules.
To launch your application with Node.js, you just need to use the module option, and select the
commonjs module kind. Our candy repository contains all basic node packages (
express, …), which are ready to use and just need to be included in your
pom.xml. To run your application with node (assuming that you do not use the DOM and that you have installed the right packages with
npm), just type the command line:
> node path/to/Main.js
Main.js is the entry point of your program, i.e. the module that corresponds to the Java class where the
main method is defined.
JSweet transpiler provides the following options. You can modify your
pom.xml to tune way your files are transpiled. Note that this option list only shows the most co is not commonly used transpiler options. For a complete (advanced) list, see the org.jsweet.JSweetCommandLineLauncher class.
|ES3, ES5, ES6
|The module kind (none, commonjs, amd, system or umd).
|JS files output directory
|Specify where to place generated TypeScript files.
|Do not compile the TypeScript output (let an external TypeScript compiler do so).
|Java source files to be included
|Source files to be excluded
|Bundle up all the generated code in a single file, which can be used in the browser. The bundle files are called ‘bundle.ts’, ‘bundle.d.ts’, or ‘bundle.js’ depending on the kind of generated code. NOTE: bundles are not compatible with any module kind other than ‘none’.
|Specify the location where debugger should locate Java files instead of source locations. Use this flag if the sources will be located at run-time in a different location than that at design-time. The location specified will be embedded in the sourceMap to direct the debugger where the source files will be located.
|Force the Java compiler to use a specific encoding (UTF-8, UTF-16, …).
|Skip the root directories (i.e. packages annotated with @jsweet.lang.Root) so that the generated file hierarchy starts at the root directories rather than including the entire directory structure.
|Turn on all levels of logging.
|Set the JDK home directory to be used to find the Java compiler. If not set, the transpiler will try to use the JAVA_HOME environment variable. Note that the expected JDK version is greater or equals to version 8.
|Generate the d.ts files along with the js files, so that other programs can use them to compile.
|Ignore definitions from def.* packages, so that they are not generated in d.ts definition files. If this option is not set, the transpiler generates d.ts definition files in the directory given by the tsout option.
|Use the given factory to tune the default transpiler behavior.
|A file that contains a header to be written at the beginning of each generated file. If left unspecified, JSweet will generate a default header.
|The directory JSweet uses to store temporary files such as extracted candies. JSweet uses ‘.jsweet’ if left unspecified.