This is a modification of the JSweet quick start demonstrating how to compile Java to JavaScript to run on Cloudflare Workers
> git clone https://github.com/koeninger/jsweet-quickstart
> cd jsweet-quickstart
> npm run build
> wrangler publish
You can also watch your JSweet (.java) source files for modifications using
mvn clean jsweet:watch
It will transpile automatically when you save a source file. Be sure that there are not transpilation error in your console, though.
At any time, you can modify the Java files (or add new files) and run npm run build to generate the corresponding JavaScript files.
You can modify the generation options by modifying the plugin section for jsweet-maven-plugin in pom.xml. Check the Maven plugin for the full option list.
If you want to use a JavaScript library, you must add the Maven dependency in the <dependencies> section of the pom.xml. You can copy-paste the Maven dependency description from our Candy browser, or from our online Maven repository. When running mvn generate-sources with a new library, if available in the candy, the JavaScript library will be extracted to the location given by the candiesJsOut option (here in the webapp directory). JavaScript libraries are packaged in the Jar following the WebJars conventions. When not available, you will need to find and download the JavaScript library manually (or using a third-party tool such as Bower).
- Java 11 JDK is required. Type in
java -versionin a console to make sure that you have a >11 JDK. - The
nodeandnpmexecutables must be in the path (https://nodejs.org). - The
tscexecutable must be in the path (https://www.typescriptlang.org/download) - Install Maven (https://maven.apache.org/install.html).