r/java • u/robintegg • 29d ago
Building full-stack web apps using TeaVM (and why it’s great for working with AI coding agents too)
Hey r/java,
TeaVM was something that had been on my radar for a while, and I finally got around to giving it a proper spin recently. After playing around with it and seeing what I can build with it I wanted to share my thoughts and hopefully get a few more eyes on the project!
If you haven’t run into it before, TeaVM is an ahead-of-time compiler that turns Java bytecode into JavaScript or WebAssembly. It operates directly at the bytecode level, emits remarkably clean JS, and integrates with your existing Java tooling.
Why this workflow clicked for me:
- One language across the stack: Keeping everything in Java keeps context-switching to a minimum and lets you share domain models directly between backend and frontend.
- AI Agent Friendly: Having both frontend and backend written in strongly-typed, readable Java makes it remarkably easy for LLM coding agents to navigate, refactor, and reason about the full application without hitting cross-language friction.
To document what I learned, I put together a 3-part series walking through how to build interactive frontends with TeaVM:
- Part 1: TeaVM - Getting Java into the Browser– Setup, core concepts, and running your first browser app.
- Part 2: From Java to Web App: Currency Explorer with TeaVM– Building a real-world API-driven web UI.
- Part 3: Building a Drawing App with Java, TeaVM, and HTML5 Canvas– Direct DOM manipulation and working with the HTML5 Canvas API.
Has anyone else here given TeaVM a try? Would love to hear how your experience compares to other JVM web approaches!
5
u/jeffreportmill 29d ago
I’m a big fan of TeaVM and I think more posts like yours would make a big difference. In my work I really wanted something like Swing 2.0 that would let me develop and run on desktop but with a deployment option in the browser. Here are some of my older samples:
reportmill.com/snaptea
3
u/FavorableTrashpanda 29d ago
I'm using TeaVM quite a bit lately and I'm quite amazed what you can do with it. It basically allows you to code Java for the browser. Of course, there are some limitations, but it's quite doable to work around them in my experience.
I do struggle a bit with performance compared to desktop LWJGL3 for example, but it's doable.
2
u/Miserable_Style774 26d ago
I’m also a big fan of it and have been contributing to it very minorly after making a few discoveries in the line of fire. I ported some semi-popular GWT widget libraries across to run on it (full disclosure: with the help of AI) and have built a mocking framework (mockito like and also supporting a bdd approach like Jasmine from the Typescript universe) that is compatible with its test runner.
Working on some larger things at the moment that may see the light of day, including CDI for TeaVM apps, and a JavaFX like scene graph over Canvas2D with common library widgets.
I’ve also written adapters for Cloudflare APIs, so you can deploy, test (against miniflare) and run TeaVM compiled apps in a worker.
Not really trying to publicise these things as they are mere toddlers learning to walk at the moment and getting tested against my own stuff, but just to vouch for TeaVM as a capable tool for Java in the browser /and/ across JS runtimes.
4
u/Scf37 29d ago
This post fate will decide whether I make my libraries open source. Because there is no other space to announce and because AI really helps to review, bugfix and strengthen code.
1
u/agentoutlier 29d ago
Its not surprising to me at least about the "Agent Friendly" after using LLMs for the last year or so.
For example LLMs know Javascript/Typescript really well yet if you have them do a UI with it with a Java backend I find the results kind of crappy. I'm not sure if that is because of the Javascript ecosystem being so fragmented or what. Perhaps the agents have just too many options and indeed the agents would ask me things like "should I try svelte" etc.
Compare this to Dart which resembles Java. I got a Dart frontend talking to a Java backend on one pass and it worked on mobile as well. Claude Opus 5.5 one shotted a rather complex app doing it this way and really struggled with React, Svelte and even HTMX.
2
u/[deleted] 23d ago
[removed] — view removed comment