https://blog.kie.org/2022/04/rise-of-j2cl-java-web-development-after-gwt.html KIE * All * Tools * Process * Rules * Optimization * AI * General * Kogito * Drools * jBPM * OptaPlanner KIE Community [yH5BAEAA][8c543d86] Rise of J2Cl: Java web development after GWT by Dmitrii Tikhomirov - April 11, 2022 Tools Article [yH5BAEAAAAALAAAAAABAAEAAAIBRAA7] [barn-images-t5YUoHW6zRo-unsplash-1-1-1024x683] It looks like 15 years of GWT are coming to the end, and besides that web development has dramatically changed since 2006. There is now no chaos of conflicting browser implementations that require to run multiple permutations each. At the same time modern web development frameworks are far from ideal. For instance, a very strong advantage of GWT was the ecosystem around Maven - the stability and usability of this solution was incredible, especially when big teams worked on large projects. Google, the main developer of GWT, left the project and started J2CL, the successor of GWT, which takes the very best practices to a new level. Their documentation calls it out as being used in many high performance projects such as Gmail, Inbox, Docs, Slides, and Calendar. Initially J2CL was developed to be used in the Bazel environment. After several years of hard work the community, led by Colin Alworth, released the first public J2CL version for Maven - j2cl-maven-plugin. So let's take a look at what it is and how it works. J2CL and Closure Compiler J2CL is responsible for only one task - to transpile a set of Java classes into a set of JavaScript files. Google's Closure Compiler is responsible for merging this set of javascripts into one executable JS script, its optimization and minification. Closure Compiler is extremely efficient in minification and optimization of the JavaScript, it simply has no competitors. Generating our first J2CL project Let's start from a simple one module application. Luckily for us, we can generate it from a pre-build archetype. Download the archetype if you don't have it: mvn org.apache.maven.plugins:maven-dependency-plugin:get \ -DrepoUrl=https://repo.vertispan.com/j2cl/ \ -Dartifact=com.vertispan.j2cl.archetypes:j2cl-archetype-simple:0.19 Now we can generate a simple application: mvn archetype:generate -DarchetypeGroupId=com.vertispan.j2cl.archetypes \ -DarchetypeArtifactId=j2cl-archetype-simple \ -DarchetypeVersion=0.19 Let's take a look at the result: +-- pom.xml +-- src +-- main | +-- java | | +-- org | | +-- treblereel | | +-- j2cl | | +-- App.java | | +-- App.native.js | +-- webapp | +-- WEB-INF | | +-- web.xml | +-- css | | +-- simpleapp.css | +-- index.html +-- test +-- java +-- org +-- treblereel +-- j2cl +-- AppTest.java - App.java is a starting point of our application and there's is one point I have to highlight below. - App.native.js used to specify how to start our application to the Closure Compiler, because it knows nothing about it. Usage of native.js is a very large topic and a separate article can be written about it. - AppTest.java is just a J2CL-compatible unit test that runs in HtmlUnit, it's also possible to use ChromeDriver to run it in a real browser but it takes longer. - pom.xml - here the only interesting part for us is the j2cl-maven-plugin section. For now it contains only the declaration used to set which level of optimization we are going to use during the compilation of the project. ADVANCED is the most efficient one, so Closure Compiler does aggressive renaming, dead code removal, global inlining and so on. But in some cases Closure Compiler needs our help and care - we have to declare which properties or methods should not be removed or renamed. BUNDLE is less strict and better suitable for development because each compilation round takes less time compared to ADVANCED. Running and building our J2CL application j2cl-maven-plugin allows us to run our application in the development mode with build-in hot code reload and source map debug. To start devmode, run the following command in the terminal: > mvn j2cl:watch When the application started, run the following command in the second terminal: > mvn jetty:run There is no need to run 'mvn clean' each time because J2CL will recompile everything from scratch, and we can reuse the results from the previous run. Moreover, there is an option to use global cache between several projects to reduce compilation time. To build '.war' we should run 'mvn package', there is nothing new here, everything is pretty familiar to GWT developers. Ok, what is new compared to GWT * GWT modules are gone, yes, no more modules. So J2CL will try to compile direct and transitive dependencies from pom.xml, that is why we should set 'provided scope' to annotation processors and shade them. * GWT.create gone as well * GWT generators are gone, now we should use APT-based generators. * What about GWT components and widgets we used before ? Most of them have been ported to J2CL. * Does @GwtIncompatible work? Yes, it is still here. And what is the value of it for us? Right now we are focused on migration of our existing projects from gwt2 to j2cl. There are many libraries that have been migrated to j2cl and there are many libraries that support gwt2 and j2cl. I would like to highlight elemental2-* wrappers, DominoKit, Nalu, and many others. Gwt2 has been ported as gwtproject - set of migrated modules. Errai framework - the core component of our applications has been re-implemented as Crysknife project. In the upcoming posts i am going to address several topics: * Existing libraries and frameworks that are J2CL-compatible * Defines - how to propagate variables to J2CL * How we can improve generated code with native.js * Externs - why do we need them and how to write our own externs * Semi-reflection * Interoperability with TS * And maybe many more 5 1 vote Article Rating Subscribe Connect withD Login I allow to create an account When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account. DisagreeAgree Notify of [new follow-up comments ] [ ] [>] guestguest Label[ ] [ ] [ ] Name* [ ] Email* [ ] Website [ ] [Post Comment] Connect withD I allow to create an account When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account. DisagreeAgree guestguest Label[ ] [ ] [ ] Name* [ ] Email* [ ] Website [ ] [Post Comment] 0 Comments Inline Feedbacks View all comments Load More Comments KIE * Blog * Kogito * Drools * jBPM * OptaPlanner Featured posts All posts [ ] x Archive Feed Type [ ] Article (1378) [ ] Event (88) [ ] News (48) [ ] Presentation (61) [ ] Release (81) [ ] Video (35) Authors [ ] Mark Proctor (577) [ ] Kris Verlaenen (228) [ ] Maciej Swiderski (105) [ ] Geoffrey De Smet (94) [ ] Edson Tirelli (72) [ ] Michael Neale (59) [ ] Tihomir Surdilovic (45) [ ] Salaboy (42) [ ] Eder Ignatowicz (34) [ ] Geoffrey De Smet (31) [ ] William Siqueira (20) [ ] Marian Buenosayres (18) [ ] Manaswini Das (18) [ ] Karina Varela (18) [ ] Matteo Mortari (15) [ ] Cristiano Nicolai (14) [ ] Guilherme Carreiro (14) [ ] Mario Fusco (13) [ ] Luiz Motta (13) [ ] Paulo Martins (12) [ ] Guilherme Caponetto (10) [ ] Edoardo Vacchi (9) [ ] Sotty (9) [ ] Toni Rikkola (8) [ ] Sadhana Nandakumar (7) [ ] Francisco Javier Tirado Sarti (6) [ ] Tiago Bento (6) [ ] Gonzalo Munoz Fernandez (6) [ ] paul browne (6) [ ] Gabriele Cardosi (5) [ ] Jacopo Rota (5) [ ] Alessandro Costa (5) [ ] Tommaso Teofili (5) [ ] rsynek (4) [ ] Michael Anstis (4) [ ] wmedvede (3) [ ] Rui Vieira (3) [ ] Luca Molteni (3) [ ] Valentino Pellegrino (3) [ ] Tiago Dolphine (3) [ ] Christopher-Chianelli (3) [ ] Ruben Romero Montes (3) [ ] Toshiya Kobayashi (3) [ ] Ricardo Zanini (3) [ ] Kirill Gaevskii (2) [ ] Thiago Lugli (2) [ ] Diego Torres Fuerte (2) [ ] Daniel Jose dos Santos (2) [ ] Yeser Amer (2) [ ] Wagner Lemos (2) [ ] Rebecca Whitworth (2) [ ] triceo (2) [ ] Adriel Paredes (2) [ ] MusaTalluzi (2) [ ] Rishiraj Anand (2) [ ] Enrique Mingorance Cano (1) [ ] pauljamesbrown (1) [ ] Saravana Balaji (1) [ ] mariofusco (1) [ ] Donato Marrazzo (1) [ ] Michael Perez (1) [ ] Abhishek Kumar (1) [ ] Handrey Cunha (1) [ ] Leonardo Gomes (1) [ ] Trevor Royer (1) [ ] sudheerchekka (1) [ ] Joe White (1) [ ] mcimbora (1) [ ] Hao Wu (1) [ ] Andrew Waterman (1) [ ] Rob Geada (1) [ ] Jiri Locker (1) [ ] michaltomco (1) [ ] Jaroslaw Kijanowski (1) [ ] oskopek (1) [ ] Lubo Terifaj (1) [ ] Roberto Emanuel (1) [ ] Dmitrii Tikhomirov (1) [ ] tdavid (1) [ ] Jaime Enriquez Parada (1) [ ] jgoldsmith613 (1) See more Tools Today Rise of J2Cl: Java web development after GWT by Dmitrii Tikhomirov Editing Serverless Workflow definitions with our n... by Paulo Martins Last 6 months KIE Tools Examples - Implementing a Ping Pon... by Thiago Lugli JSON DataSets in Dashbuilder by William Siqueira KIE Sandbox: top 7 key new features by Eder Ignatowicz CUSTOMIZE PATH AND NAME OF GENERATED DMN/BPMN SVGs... by Thiago Lugli Deploy your KIE Sandbox to OpenShift by Guilherme Caponetto Calling Java from DMN by Donato Marrazzo Announcing DashBuilder 0.14.1 by William Siqueira Smart Scroll for BPMN/DMN Editors by Wagner Lemos Kogito Tooling Released! 10k+ installs on BPMN ext... by Eder Ignatowicz Automatically generate BPMN/DMN SVG on VS Code by Eder Ignatowicz Business Central SSH Key-Based Authentication by Eder Ignatowicz Last Year Better reusability features on BPMN data types by Jaime Enriquez Parada Developing business processes more efficiently wit... by Paulo Martins Visualize, Edit, and Share your BPMN, DMN and PMML... by Eder Ignatowicz New DMN Boxed Expression Editor - What'... by Valentino Pellegrino Manage Processes and Tasks using Kogito consoles by Saravana Balaji An object model marshaller for all occasions by Michael Anstis Automatic connections with Line Splicing by Handrey Cunha BPMN and Metadata - Leveraging app capabilit... by Wagner Lemos DMN editor - Contributors Guide - Part 2 by Guilherme Carreiro Deploy decisions to DMN Developer Sandbox by Guilherme Caponetto Kogito Tooling 0.12.0 Released! by Eder Ignatowicz Four steps to author BPMN and DMN assets on gitpod... by Guilherme Caponetto How to develop better web widgets with showcase ap... by Valentino Pellegrino Add data from KIE execution server for authoring d... by Manaswini Das Kogito Tooling i18n update by Luiz Motta Bend-points and the DMN Editor by Daniel Jose dos Santos Add SQL datasource for authoring dashboards by Manaswini Das All posts - Back to top wpDiscuz 0 0 Would love your thoughts, please comment.x () x | Reply [ ] Insert CC by 3.0 | Privacy Policy Sponsored by [logo]