10 ms·
New Java to WASM GC Transpiler: Run Java in the Browser, No Plugin Required
- TeaVMFan 2y agoThe new release of TeaVM (0.11.0) now supports WebAssembly GC. This increases performance while further decoupling TeaVM apps from ECMAScript. TeaVM ( https://teavm.org/ https://teavm.org/ ) is an Apache-licensed project, free for use in commercial projects. It is mature and used widely, including in frameworks like Flavour ( https://frequal.com/Flavour/book.html https://frequal.com/Flavour/book.html ) and more projects listed here: https://www.frequal.com/TeaVM/TeaVmBasedSites.html https://www.frequal.com/TeaVM/TeaVmBasedSites.html TeaVM compiles Java code to run in the browser, efficiently and quickly. It features short build times, small downloadable files, and a batteries-included toolset (including minification, tree-shaking, and packaging). Previous releases have conquered all similar open-source tools (that support threading) in independent testing: https://renato.athaydes.com/posts/comparing-jvm-alternatives-to-js.html https://renato.athaydes.com/posts/comparing-jvm-alternatives...
- pestatije 2y agowhats the status of swing? can we port old applets easily? multi-threading or am i dreaming?
- TeaVMFan 2y agoNo Swing support at present. There is an issue filed, but it is in need of an implementer: https://github.com/konsoletyper/teavm/issues/406 https://github.com/konsoletyper/teavm/issues/406 I made a general guide for migrating from Swing to TeaVM here: https://frequal.com/TeaVM/migration/MigratingFromSwingToTeaVm.html https://frequal.com/TeaVM/migration/MigratingFromSwingToTeaV... For a more specific example, I ported an open-source Java applet and described the process here: https://frequal.com/java/RestoringA19YearOldGameWithTeaVm.html https://frequal.com/java/RestoringA19YearOldGameWithTeaVm.ht...
- invalidname 2y agoYou can use Codename One whose web port is based on TeaVM. The API is very much like Swing. Albeit more focused on mobile.
- TeaVMFan 2y ago+1 for for Codename One. It is the only tool I use when I need a mobile-only app. I have built numerous apps using Codename One, and have released 2 of them in app stores. Great Swing-like API, great examples, great documentation.
- shannah78 2y agoI think Swing is a non-goal of this project. It provides good interop with the DOM and core JS methods, and it makes it easy to create your own interop for JS apis that aren't in the core. There are at least two GUI toolkits that run on TeaVM: 1. Codename One. Similar to swing, but focused on mobile https://www.codenameone.com https://www.codenameone.com 2. SnapKit. Targeted at desktop. Also a light-weight toolkit, like Swing. https://github.com/reportmill/SnapKit https://github.com/reportmill/SnapKit
- peutetre 2y ago> I think Swing is a non-goal of this project. It could work though by drawing to canvas. That's what Avalonia does in C#: https://avaloniaui.net/ https://avaloniaui.net/ Here's a clone of Visual Basic 6 written with Avalonia and compiled to WebAssembly: https://bandysc.github.io/AvaloniaVisualBasic6/ https://bandysc.github.io/AvaloniaVisualBasic6/ https://github.com/BAndysc/AvaloniaVisualBasic6 https://github.com/BAndysc/AvaloniaVisualBasic6
- red1111 2y agoIf that's your goal, you should look at CheerpJ, which supports Swing and has the goal of making it so you can easily port applets and other existing apps to the web. I think TeaVM is more focused on letting you share code with the web instead of porting entire apps.
- seinecle 2y agoLove the concept but no clear idea of a use case. Could you list 3 or 4 of them please?
- pjmlp 2y agoBring Java Applets back would be one.
- palmfacehn 2y agoJS frontend enthusiasts rationalized JS on the backend. Now Java backend enthusiasts can once again rationalize Java on the frontend. I would consider this for a project where I already have Java code on the backend and rewriting it for the front end in JS is a bigger barrier than adding TeaVM to the stack.
- skerit 2y agoI'm actually in the process of converting my own little JS framework to Java using TeaVM. It's interesting and fun
- ffsm8 2y agoAren't ppl like that are more likely to use vaadin and similar frameworks?
- TeaVMFan 2y agoVaadin has a restrictive, commercial license. By contrast, TeaVM is Apache-licensed, available for commercial use without any gotchas, limits, or entanglements.
- konsoletyper 2y agoTeaVM author here. Personally I use it to bring a large (500KLOC) project that's written in Java and Kotlin to the browser (also we are using Graal VM Native Image to compile the same app to iOS, and Android supports). It's virtually impossible to maintain another 500KLOC code base on TS and on Swift and make sure that they behave and look 100% same. So the target audience is any team that wants to write in Java and/or Kotlin applications that works in JVM as well as in the browser.
- jurmous 2y agoI am more enthusiastic with Kotlin also compiling to wasm with Jetpack compose and now working in all major browsers. It provides a full modern UI framework and also compiles to mobile and desktop. Code is also usable on server and if using the JVM fully interoperable with Java.
- konsoletyper 2y agoTeaVM supports Kotlin as well. The difference with Kotlin/Wasm is that with Kotlin/Wasm you are limited only to Kotlin and can't use any code written in Java.
- pjmlp 2y agoTry calling Kotlin co-routines from Java, fully interoperable is it not. Additionally I really dislike the anti-Java discourse in Kotlin circles, as if Kotlin was able to stand on its own, without the Java ecosystem, or Google's making it Java replacement on Android.
- banashark 2y agoI didn’t get a sense of anti-java-ism from the parent poster. While I enjoy Kotlin more than Java I see the benefits of both, and from most folks I’ve spoken to about the two they seem fairly level-headed about the situation. I think that for all language discussion online that there is a very small percentage of people that get over-inundated by the emotional feeling of “investing their time” into a language and wanting to not feel like they made a mistake or that their time was a waste. I wish f# got the same treatment Kotlin did tooling wise, because if I were to compare the “interoperability” of the two with the incumbent on their respective VMs, my experience has shown that developing with Kotlin incurs much less friction on a day-to-day basis. I have no doubt that part of that friction is due to the radically differing foundations that f# vs c# were built on, which as a positive for f# gives it some very cool features that Kotlin won’t have, but it leads one to ponder the RoI of diverging from the primary language. I do agree with you that googles choice to adopt Kotlin for android rather than invest further into modernizing the jvm capabilities to allow for Java to be able to keep up better was definitely a boost to Kotlin, I assume they made that choice in a calculated manner. I also wonder if Kotlin would be seeing as much server side use at places like Google, was, Airbnb, etc if not for that move on googles part.
- worik 2y agoIronic, given Java Applets were going to run in browsers
- pjmlp 2y agoThey were running, not going to, until Java 8. While Java Kernel did improve download times against Flash, the latter tooling was much better, and still downloaded faster. Had it not been for Apple and iOS forbidden, mostly due to app store than security concerns, and classical plugins would be around. Since browsers never contended themselves with being document only, leaving the rest for native apps, now we have plugins back.
- worik 2y ago> They were running, not going to, until Java 8. Back in the '90s I tried hard, and succeeded, in getting Java applets to work in a browser If I recall correctly it was clunky and quite annoying. Flash succeeded, sort of, but was also clunky. But I think both were ahead of their time.
- pjmlp 2y agoLove the revenge of plugins. We might have lost a decade since Unreal was running on Flash Crossbridge, yet thanks to Web trying to be a app platform to replace native apps, we are back full circle. Java, .NET have their plugins back, even if with additional turtles along the stack, and stuff like Flutter are the new Flash. I guess, thanks to all WebGL, WebGPU and WebAssembly folks
- flohofwoe 2y agoJava plugins were mainly useful to do naughty things (for instance in a previous life I used a Java plugin to load and call into a native DLL via JNI which spawned a Win32/D3D9 game client inside a browser by attaching as a child window of the Java plugin canvas). Fun stuff but not really a good idea from a security point of view ;) And of course this cannot be replicated with a Java plugin running in a (browser) WASM engine.
- pjmlp 2y agoAll code can be abused for naughty things, including crypto miners in modern Web APIs.
- TeaVMFan 2y agoTrue, but are people turning off ECMAScript/WASM in their browsers to avoid this? As an app developer, I want to know if my app will keep running. In the Java Applet days, at some point the security scares became frequent enough to cause articles like "Turn off Java except on websites where you are actively using it". Once your users have to find and toggle a setting to make your app work, your audience size drops significantly. I don't see such fears around ECMAScript/WASM. Since the dominant players have a vested interest in users feeling safe leaving those technologies turned on for all websites, they'll keep investing to maintain that safety (and the marketing of that safety). This is a massive insurance policy for building a TeaVM app -- the foundational web technologies it builds on are receiving incredible investments from industry heavyweights. It's not just security that is maintained, new Web APIs are regularly developed too. Want to use USB from your web app? No need to wait for Oracle to roll out a Java API for it -- browser vendors have made a new API and you can call it from you TeaVM app right away.
- darthrupert 2y ago[flagged]
- Alifatisk 2y agoDoes it support JavaFX applications aswell, that would be very cool? Last time I had to recreate a project in Flutter.
- jsiepkes 2y agoNo TeaVM doesn't do Swing or JavaFX. But WebFX does: https://webfx.dev/ https://webfx.dev/ Gluon also has a cool JavaFX in the browser demo but I think it's dead: https://gluonhq.com/developer-preview-for-javafx-inside-a-web-browser/ https://gluonhq.com/developer-preview-for-javafx-inside-a-we...
- mike_hearn 2y agoYou could also check out https://jpro.one https://jpro.one which is a commercial solution but very impressive - and because rendering is server side, very fast as long as you're in the same continent as the server. The website is itself served by JPro. Of course you could also just distribute such apps as desktop apps... I will happily sell you a product that makes doing that easy :) https://hydraulic.dev/ https://hydraulic.dev/
- RyanHamilton 2y agoFor those looking a way to run java console apps in the browser, check out doppio: https://plasma-umass.org/doppio-demo/ https://plasma-umass.org/doppio-demo/ it's old and unmaintained but it works. For example I run the java H2 database online: https://www.timestored.com/data/h2-database-online/ https://www.timestored.com/data/h2-database-online/ which allows me to try disposable SQL queries in my browser.
- TeaVMFan 2y agoThe in-browser H2 database is very cool, thanks for sharing. I'm a regular user of H2, but have only used it server-side so far. How much trouble was it to get working? Not sure how doppio handles the absence of raw TCP connections and a standard filesystem in the browser, but if it works in doppio I would think it could work in TeaVM too.
- sebazzz 2y agoWould be cool if it had applet support. There used to be a very cool physics website, with all concepts explained using simulations running in Java Applets. Lost forever.
- shannah78 2y agoA little over 10 years ago, I ran across TeaVM for the first time (probably) on GitHub. We had been looking for a way to port Codename One to the web, but we needed thread support, which wasn't supported by any existing solutions. I emailed Alexey (the creator of TeaVM) to ask if he had plans for thread support, and he replied that, while "proper" threads weren't possible, he had some ideas for supporting green threads. Over the following 6 months or so, Alexey would share updates on progress he had made on the thread front. In March 2015, he shared that he had found a new approach for async code that wouldn't affect the performance of single-threaded code, and would support natural stack traces. We released a preview of our web port using TeaVM a month later, and it exceeded all of our expectations, both in how easy it ended up being to do the port (because of TeaVM), and on the performance. Alexey's solution for supporting threads, was truly a piece of genius. Had he not created TeaVM, and added threading support, I don't think we would have ended up with our web port - or, at the very least it wouldn't have ended up performing nearly as well.
- k4st 2y agoWhat was his solution?
- LoveMortuus 2y agoI'm sorry if this is a dumb question, I don't really know a lot about this field. Would this allow me to play Puzzle Pirates (a Java game) in the browser, or would the developers still need to do some work for the game to be actually playable in the browser?