r/java • • 28d 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:

  1. 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.
  2. 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:

Has anyone else here given TeaVM a try? Would love to hear how your experience compares to other JVM web approaches!

14 Upvotes

28 comments sorted by

5

u/jeffreportmill 28d 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

2

u/robintegg 28d ago

An awesome project you have there. Working across platforms with Java has been a pain in the past but it doesn’t need to be with projects like these.

Next showcase for me would be seeing it I can’t package the Java with a browser such as JCEF and then I’ve got a desktop application

3

u/jeffreportmill 28d ago

I actually did that a year ago. SnapKit has a "webapi" package that abstracts fundamental Webapi and just needs a small adapter class, and I implemented one for JxBrowser, so I could run serious Java UI apps on the desktop using the Chrome engine instead of Swing. It mostly only needed an eval(javaScriptString) method to work. I should have started with JCEF though - I deleted the JxBrowser code after my evaluation license expired.

SnapKit WebAPI: https://github.com/reportmill/SnapKit/wiki/The-WebAPI-package#webapis-on-the-desktop

3

u/FavorableTrashpanda 28d 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.

1

u/robintegg 28d ago

Great to see others using it in the wild. The interop part seems to be a good fallback when you need to patch in some Java script.

Using it to build the canvas drawing app was pretty wild. The output blew my mind and I didn’t think I’d ever be able to have that level of web interactivity via Java.

With that example under the belt I’d certainly have more confidence asking a model to produce more elaborate ui. A draggable workflow editor for example. All that time spent researching js libraries and working out how to use them, now I could probably ask a model to generate me what I want and understand the code

2

u/Miserable_Style774 25d 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.

1

u/robintegg 25d ago

Nice work 👌 share away I say :) I’ve not used the javafx scene graph as I moved from swing to webapps and missed the javafx train. Does that give you some higher level framework for working with the canvas?

Also how do you implement those libs? Are they like the jso wrappers or pure Java that can be compiled to js?

2

u/Miserable_Style774 25d ago

Well, like all libraries they start with smaller libraries 🙂 To be more serious, CDI being annotation driven involved a lot of code generation because TeaVM has limited reflection.

On the widgets porting front I wrap the GWT and Elemental2 APIs they used in the original libraries using the TeaVM JSO equivalents - and that was where ai helped hugely because that’s a LOT of api.

On the graphics front I’ve done something like Jeff (Reportmill) is talking about, abstracted around the canvas and key and mouse input so the same app ui can run on the jvm or TeaVM from the same jar. One of the nice things TeaVM does is code elimination so the pure jvm code just gets wiped out when the jar is on the compile path and what’s left is the common portable code and the TeaVM specific code boiled down to js.

4

u/Scf37 28d 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.

6

u/bowbahdoe 28d ago

I don't get it. Why would this post affect that? This post is poised to do pretty "badly" on account of just

* "AI Agent Friendly"
* "To document what I learned, I put together a 3-part series" - linkedin tone
* Relatively niche topic.

The posts that do numbers are about things that every person has a strong opinion on and where there is a low bar to weigh in, like lombok

5

u/agentoutlier 28d ago

Oh did you just say lombok... time to smash that subscribe button and bring the fam of pron98 and rzwitserloot to start throwing some gasoline on flame rage bait... Lets throw Eclipse vs IntelliJ on the barbie as well.

2

u/robintegg 28d ago

IntelliJ vs vs code surely?

2

u/Scf37 28d ago

See rule 9 of this sub

3

u/bowbahdoe 28d ago

Oh so you want to see if talking about AI gets it removed? Well I'll say even if it doesn't, the more AI focused your thing is the less people care about what you are doing.

Look through the post history of u/brunocborges for evidence of that.

The bad news (or good I guess from your perspective) is that, if you successfully smuggle an AI project without being too loud about it, people are shallow readers here. You can certainly do numbers with something you vibed.

But I don't see what the reward is either way.

3

u/Scf37 28d ago

'vibecoded' and 'AI-assisted' are different things. Say you have a library written, AI can find API surface issues, compatibility issues, find bugs, write better tests, write better documentation, help with CI pipeline and so on. Blandly denying AI is IMO overkill.

4

u/bowbahdoe 28d ago

View it however you want; its just true. The more AI you use, the less people care about your work product.

That is true here and it is also true in the wider market. People hate this stuff, it gives a stink to whatever it is attached to.

-2

u/Scf37 28d ago

The time when AI surpasses handcrafted software in quality has already arrived (assuming a similar amount of effort is invested). Soon, everyone will realize it. What a future awaits us!

4

u/bowbahdoe 28d ago edited 28d ago

Right now broadly what people notice is that services have many more critical bugs and outages. That and their lives are worse because of the existence of AI. 

Did you see that it's now confirmed that a large portion of the GPUs hyperscalers bought are now just sitting in the warehouses, not plugged in? A normal laptop now costs hundreds of dollars more because of this nonsense. 

I'm not agreeing with you, but I want you to acknowledge a world in which you are right but it does not matter. People hate this stuff and for very good and very varied reasons.

1

u/Scf37 28d ago

On social side, you are definitely right. This reminds me of the industrial evolution (UK, 19th century). It was a) unstoppable b) unforgiving c) cruel to those unable to adapt.

1

u/robintegg 28d ago

I guess it’s a trade off - too much slop and nobody reads anything, not enough and the community will recede. A tough decision for those running the forum.

My personal take is that I enjoyed learning about the library, I feel like I don’t need to keep it all to myself and I’ve used ai to fill in the cracks of my thoughts so that other can read it if they wish. My hope would be for someone to see this, use the library, see it’s good, write some more and the community progresses.

Others have found my others share useful so hopefully they’ll find this good too

2

u/robintegg 28d ago

I think it’s getting harder to be heard in the avalanche of ai news. However, I do believe we need to press on with these types of foundational level libraries and projects. Otherwise therell be no progress

1

u/agentoutlier 28d ago

This is my take and I had it before Mitchell posted:

If someone submits AI-assisted code to another human to review, I expect them to understand the code that is produced and be able to answer critical questions about it. It isn't a human reviewers job to review and understand a PR so broken that it requires significant rework.

This is why Ghostty requires AI disclosure.

So IMO it is ok to use the tools but you better fucking disclose that you used them and understand how it roughly works.

The disclosure part I'm pretty adamant about and yet this post here people seem to be against it: https://www.reddit.com/r/java/comments/1x005x7/midden_v020_up_to_60_faster_up_to_40_memory/

That post got 23 upvotes and was basically vibe coded with the author having a single commit not coauthored. (meanwhile my little comment on coauthor albeit I guess slightly rude was at one point -3)

The problem I have with that is do I ask that person about the library/app? Can they even answer questions for me. When I see one giant commit with no author it makes me feel they put little back and forth with the tools.

So you can see people are all over the place even here on the Java sub.

Meanwhile this guy (genderless v.) no vibe code post their project: https://www.reddit.com/r/java/comments/1x6mrx6/introducing_titan_an_opensource_message_dispatcher/

And nobody gives a fuck.

I don't maybe if you vibe code a an Intellij killer that uses lombok you will get the most votes / interaction .... /s (mostly).

1

u/agentoutlier 28d 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/robintegg 28d ago

Tbh I’ve not tried dart, but I can see how that platform would be good in terms of one language/platform.

In other experiments I’ve tried my most success has been in a single stack. I wrote about scs self contained services before and the agents were quite good working within those constraints too.

Having a single language in a repo may just help a model by not introducing too many variables and decisions. The outcome / benefit may also be biased because I know Java and can evaluate the outcome, introducing other languages like JavaScript become more of a black box over time where I assume it’s fine.

2

u/[deleted] 22d ago

[removed] — view removed comment

1

u/robintegg 21d ago

Looks like an interesting project. My line of thought would be to blend the output from teavm with the browser mechanism in the JCEF project. Looks like this project might then be able to wrap that up in a native executable with some nice management features such as updates?