WebFX - Java To JavaScript
Written by Nikos Vaggalis   
Thursday, 15 December 2022

WebFX offers a new way to develop modern web-based Java applications with rich desktop-like GUIs. How is that possible?

It is possible due to WebFX being a JavaFX application transpiler powered by GWT which can transpile a JavaFX application into a traditional self-contained pure JavaScript web app with no plugin or server required for its execution in the browser.

That means that if you are responsible for a legacy JavaFX application or are developing under the revamped JavaFX as Openjfx you can now port your application to the web without having to rewrite it.

Of course, that's due the magic of the transpiler. We have explored that notion in "A Compiler Writing Playground"

Another example is the case of Typescript which adds optional typing (on that matter make sure to also check Sorbet - Making Ruby Statically Typed) to Javascript, acting as a statically typed and better superset of it. The TypeScript compiler analyzes and compiles the TypeScript code into JavaScript in order to run on any browser. 

Fable, is yet another X-to-Javascript transpiler. Fable transpiles F# to ES2015 JavaScript so code written in F# can run anywhere JavaScript runs - the browser, Node. js, Electron, React Native or generally V8.

So you can convert applications and languages that sound like misfits, to each other.

At WebFX's core lies the WebFX kit which is a modified version of OpenJFX that can be transpiled. This is achieved by patching the higher layer of OpenJFX (which contains the main JavaFX features and API) to make it GWT compatible, and by replacing the lower layer (the graphic rendering pipeline) by a scene graph DOM mapper (the DOM being finally rendered by the browser).

Of course by removing the Javascript barrier you can focus on writing your application in pure Java all the way. What does this remind me of? Ah, yes. . . Vaadin.

Vaadin in its beginnings used GWT under the hood to compile the Java code to JavaScript. Not anymore. Since version 10 it compiles to Web Components and through its Client side JavaScript engine communicates the events taking place browser side to the server side which decides how to proceed, in for example modifying the DOM;that is Vaadin renders the application server side and this server side endeavor goes by the name of Vaadin Flow. Hold that thought for a moment because there's a reason for mentioning it.

WebFX does not require the presence of a server however and that is one of its biggest advantages;a standard self-contained JS packaging is a much more simple, scalable and reliable execution model.

Its other advantage is that it is multi-platfrom. In addition to the web platform, a WebFX application can also run on desktops & mobiles with Gluon toolchains to produce native executables.

This ability to create applications for different platforms starkly reminded me of Jetpack Compose Multiplatform, an extension to the Jetpack Compose UI framework from JetBrains, which makes it possible to build Android, Desktop, and Web UIs with the same artifacts from a single codebase. It works on top of Kotlin Multiplatform, the SDK for cross-platform development provided by JetBrains, which is the technology the supports the code sharing.

However in order to producer native executables with WebFx you need Gluon and in extension GraalVM too. When using the GluonFX plugins (for Maven and Gradle) in a JavaFX application, developers are leveraging Gluon Substrate which provides the way to create native images for Java and JavaFX projects that can target all platforms (desktop, mobile and embedded). Under the hood, Gluon Substrate leverages the GraalVM project.

Since the project is still in the incubation phase, there are some limitations;limited JavaFX coverage, bugs in WebFX, GWT compilation errors etc. But despite the limitations, you can already develop real applications. The project's website for example has been developed using WebFX, presenting the technology through a series of animated cards.

Third party apps are shingly making their appearance too. For instance 'Modality' a free, open-source, hospitality-oriented booking system Powered by WebFX but with a server backend;Vert. x to interface between client apps and back-end services, serving the SPA.

WebFX is, of course, open source. As such on its Github repo you can find all the relevant code plus the code of the demos, to get a head start.

 

webfxlogo

More Information

WebFx

WebFx Github

Modality

Related Articles

Vaadin Reaches Version 21

A Compiler Writing Playground

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Spider Courtship Decoded by Machine Learning
07/04/2024

Using machine learning to filter out unwanted sounds and to isolate the signals made by three species of wolf spider has not only contributed to an understanding of arachnid courtship behavior, b [ ... ]



Java Version 22 Released
04/04/2024

JDK 22 is not a Long Term Support release, but is one of the regular releases that are scheduled to arrive every six months. Still, it has got a lot to show for itself.


More News

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Thursday, 15 December 2022 )