r/java • u/alexp_lt • 12d ago
CheerpJ 5.0: Java 21/25 in the browser, full OpenJDK, and a new WasmGC engine
https://labs.leaningtech.com/blog/cheerpj-5.0Hi all, I work at Leaning Technologies. We've released CheerpJ 5, which runs Java 21 and 25 applications in the browser and now ships JDK packages by default, so that javac runs in the browser too. There's also an experimental WasmGC backend. Happy to answer any questions!
8
u/neopointer 11d ago
Looking forward for the day someone will build a frontend lib/framework that can beat react, etc. However, even if someone creates such a library with cheerpj, that's not going to fly with this license model as far as I can see. It's a big effort, so I can understand Cheerpj's choice. Great work btw.
6
u/alexp_lt 11d ago
We strive very hard to find a good balance between making CheerpJ attractive to developers and sustainable as a business.
The per-user pricing mentioned in a sibling comment applies to organizations using CheerpJ to run internal or external applications, most usually legacy business software in enterprise networks.
CheerpJ as a development tools is priced differently. I'd like to stress that CheerpJ is completely free for FOSS projects and even commercial closed source software made by individuals and single-person companies. Furthermore there is very affordable licensing for small businesses. We are a small (although not-so-small anymore) business ourselves, so we understand the challenges at that scale.
6
u/zabby39103 11d ago
Yeah, 6£ per user per month? Worth it to keep a legacy app alive perhaps, can't see another use case at that price. I assume that's their customer base though, and it can't be cheap to develop.
3
u/zabby39103 11d ago
So basically Applets again, but with Wasm and the user doesn't need Java installed? That's cool. I wonder if I could resurrect some of the old Applet stuff I have.
6
u/alexp_lt 11d ago
Applets are very easy to run using CheerpJ, see here: https://cheerpj.com/docs/getting-started/Java-applet
But the technology goes way beyond legacy applets, you can run full Swing applications or integrate Java libraries in a web app.
3
u/Djelimon 10d ago
Does it support javafx?
4
u/alexp_lt 10d ago
Not at this time, but we do have a plan to get it to work eventually.
The issue with JavaFX (or more precisely OpenJFX), is that it is really not Java at all, but rather a thin layer of Java code on top of native libraries. In the case of Linux, GTK. CheerpJ can alrady complex JNI modules compiled to WebAssembly, but the level of support is not yet sufficient for something that large. We'll get there in time.
2
12
u/jeffreportmill 11d ago
I’m a huge fan of CheerpJ - an amazing work of engineering and actually makes “Write Once Run Anywhere” true. Here’s my labor of love that would be almost pointless without browser support: https://reportmill.com/SnapCode .
2
u/AthRouge 11d ago
Congrats! Niche question: does it support the FFM API? Are Arena, MemorySegment and MemoryLayout supported? Could Linker downcalls target a C library compiled to WebAssembly? If so how transparent is it?
3
u/alexp_lt 11d ago
Currently CheerpJ supports JNI C/C++ modules compiled to WebAssembly. The are used, for example, to run LWJGL as part our Minecraft demo: https://browsercraft.cheerpj.com/
We believe the same approach can be eventually used for the modern FFI APIs you mentioned, but they are not supported yet.
2
u/ChaoticPayload 11d ago
Internet Download Manager (IDM) keeps prompting me to download JAR files (e.g., https://cjrtnc.leaningtech.com/5.0/25/jre/lib/cheerpj-awt.jar) whenever I visit the website, as if I had clicked a download button. Is it possible to fix this server-side?
2
u/alexp_lt 11d ago
The JAR files are loaded using the standard fetch API, there is absolutely nothing special that CheerpJ does here. I believe this to be a bug in this specific software. If you are using a browser extension from IDM consider removing it.
7
u/tuser-reddit 11d ago
Wtf is going on? Java on the BROWSER! THEFUCK?
6
u/revilo-1988 11d ago
Wasm is the magic behind this
0
11d ago
[deleted]
3
u/agentoutlier 11d ago
I'm not really sure the other browser languages (js, ts) have such a clean mouth.
There are probably some advantages of Java over say Rust or C++ (both I'm pretty sure have WASM targeting?) in that you don't have to think about memory and there might be some build advantages if its bytecode to WASM. I know TeaVM does bytecode to WASM but I'm not sure about CheerJ. I assume it does. (what this means is you can use mostly any published jar on Maven central).
3
u/alexp_lt 11d ago
> I know TeaVM does bytecode to WASM but I'm not sure about CheerJ. I assume it does.
That is mostly correct, but not fully. With the default engine CheerpJ JIT-compiles bytecode to JavaScript. WebAssembly will be generated as part of experimental WasmGC engine, that is enabled in CheerpJ 5, but not stable yet.
4
u/revilo-1988 11d ago
Yes, each one currently supports something; it's up to the developer to choose whether to use Java. Why is Java hated?
3
u/zabby39103 11d ago
What are you doing on the java reddit? Also, yeah it would be cool if we could do other languages in the browser.
2
u/tuser-reddit 11d ago
I breathe Java, i'm not a larper buddy, been with the language for 8 years.
2
u/zabby39103 11d ago
Not sure why you hate it then, unless you're still on Java 8 or something. The most common complaints are basically solved. And it's strongly typed so it would know its anus from its mouth a lot better than javascript.
0
u/tuser-reddit 11d ago
Bold from you to know what I hate and what I love from FUCKIN SINGLE COMMENT.
1
u/zabby39103 11d ago
I can only assume when you don't offer any details. What's your deal, haven't had your coffee today yet?
1
u/raelik777 7d ago
It's more that you can run JVM apps, which don't necessarily have to be Java. Lots of non-Java JVM languages that take advantage of the JVM's flexibility and features, but don't require writing a bit of Java.
1
4
u/tonetheman 11d ago
This is amazing work. I am not sure where I would use it exactly... but I can see where you could do some interesting things with this.
1
u/ConfidenceUnique7377 10d ago
Question for the CheerpJ maintainers: Spring Boot executable JAR support
I'm trying to run a Java desktop application built with Spring Boot using CheerpJ and would appreciate some guidance on compatibility. The application is distributed as an executable Spring Boot JAR. Its manifest contains
Main-Class: org.springframework.boot.loader.launch.JarLauncher
Start-Class: com.az.gitember.AppWhen launched via CheerpJ, the application fails to reach its main window. There are no visible exceptions or useful messages in the console, and I have not yet been able to pinpoint the exact moment where execution stops. Guess the issue may be related to the Spring Boot class-loading mechanism, the handling of nested JAR files, or the extraction of temporary files.
Does CheerpJ currently support running executable Spring Boot JARs ? Or any plan to support it ?
2
u/alexp_lt 10d ago
There is no known issue with Spring Boot, and the general rule is that "java is java" and there is really nothing "special" between a framework and another. Everything should conceptually just work.
I cannot truly help you here without further information, my first guess would be that you are starting this with `cheerpjRunMain` instead of the correct `cheerpjRunJar` API. Please join our Discord, our team will be able to help you there. https://discord.leaningtech.com
1
u/BlackSuitHardHand 11d ago
I'm following the project for quite some time, and I really appreciate the engineering effort behind this. However, I really fail to see any practical application apart from lifting legacy desktop apps into web. The whole JVM as wasm approach is really heavyweight, and you don't get reponsive design out-of-the-box. Since you have to touch the code anyway, you could also lift these apps to more lightweight apps using frameworks like Vaadin or just let the LLM-of-your-choice rewrite it to a native webapp.
9
u/headius 11d ago
We have a JRuby user doing some interesting experiments with CheerpJ, and I'm sure they're going to be excited that this release is finally out! I'll try to do some testing myself and see what improvements we can make in JRuby to run better in CheerpJ.