Live data from Hacker News

New Java to WASM GC Transpiler: Run Java in the Browser, No Plugin Required

teavm.org

41–50 of 59 posts

Re: New Java to WASM GC Transpiler: Run Java in the Browser, No Plugin Required

#41
post #32

Earlier quoted context omitted.

JS 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.

Aren't ppl like that are more likely to use vaadin and similar frameworks?

Vaadin has a restrictive, commercial license.

By contrast, TeaVM is Apache-licensed, available for commercial use without any gotchas, limits, or entanglements.

Re: New Java to WASM GC Transpiler: Run Java in the Browser, No Plugin Required

#42
post #9

Love 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

Java 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) WAS…

To me, this is one of the many ingenious things about TeaVM's architecture. By using the preferred code execution mechanisms of browser vendors (WASM and ECMAScript, plus Web APIs) to deliver Java code, it ensures they can't block or shut down this delivery mechanism. They would have to cut off their noses to spite their faces.

Furthermore, since the browser vendors never want browser code to have public security issues, they work hard to find and fix problems in their sandboxes and runtimes. This of course benefits TeaVM apps as well, since they play in those same sandboxes, and gives them a level playing field with other web apps in perpetuity.

Plugin-based applets were only safe as long as Sun had clout and the browser vendors were investing less in security than the Java team.

Re: New Java to WASM GC Transpiler: Run Java in the Browser, No Plugin Required

#43
post #37

Earlier quoted context omitted.

Java 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) WAS…

All code can be abused for naughty things, including crypto miners in modern Web APIs.

True, 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.

Re: New Java to WASM GC Transpiler: Run Java in the Browser, No Plugin Required

#44

For those looking a way to run java console apps in the browser, check out doppio: 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/ which allows me to try disposable SQL queries in my browser.

The 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.

Re: New Java to WASM GC Transpiler: Run Java in the Browser, No Plugin Required

#45

Earlier quoted context omitted.

whats the status of swing? can we port old applets easily? multi-threading or am i dreaming?

You can use Codename One whose web port is based on TeaVM. The API is very much like Swing. Albeit more focused on mobile.

+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.

Re: New Java to WASM GC Transpiler: Run Java in the Browser, No Plugin Required

#46

Does it support JavaFX applications aswell, that would be very cool? Last time I had to recreate a project in Flutter.

You could also check out 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/

Re: New Java to WASM GC Transpiler: Run Java in the Browser, No Plugin Required

#47
post #37

Earlier quoted context omitted.

All code can be abused for naughty things, including crypto miners in modern Web APIs.

True, 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 si…

Good luck turning those things off in modern Web, unless you plan to have a custom browser.

Re: New Java to WASM GC Transpiler: Run Java in the Browser, No Plugin Required

#48

A 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 threa…

What was his solution?

Re: New Java to WASM GC Transpiler: Run Java in the Browser, No Plugin Required

#49

Earlier quoted context omitted.

Java 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) WAS…

To me, this is one of the many ingenious things about TeaVM's architecture. By using the preferred code execution mechanisms of browser vendors (WASM and ECMAScript, plus Web APIs) to deliver Java code, it ensures they can't block or shut down this delivery mechanism. They would have to cut off their noses to spite their faces. Furthermore, since the browser vendors never want browser code to have public security iss…

Really? What stops someone from dropping WASM support?

Re: New Java to WASM GC Transpiler: Run Java in the Browser, No Plugin Required

#50

Does it support JavaFX applications aswell, that would be very cool? Last time I had to recreate a project in Flutter.

No TeaVM doesn't do Swing or JavaFX. But WebFX does: 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-we...

This performs very poorly on whatever machine I use! https://raytracer.webfx.dev
Post reply on HN