-
-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Which Java APIs are supported? #947
Comments
The link to set of supported classes from Java standard library (https://teavm.org/jcl-report/recent/jcl.html) is mentioned here: https://teavm.org/docs/runtime/java-classes.html As for JSO, I publish both Javadocs and sources to Maven Central, which is requirement by Maven Central. By default, IDEA picks these and shows autocompletions, etc. But if for some reason you want them as separate jars, you can search on Maven Central for TeaVM artifacts of some certain version and download Javadocs. For example, for version 0.10.1, which is as for now is the latest, you can find them here: https://repo1.maven.org/maven2/org/teavm/teavm-jso-apis/0.10.1/
In the practical cases, the gap between Java and JavaScript is not fully transparent, so you can have some issues here. So it depends. Personally, I write everything in Java, because I use TeaVM primarily to compile single app both to Android, iOS (Graal Native Image) and web, sharing 99.9% of code between platforms. |
So how do you build the GUI? Do you use the classes in the org.teavm.jso.dom.html package or do you use other classes?
Could you share some more information on this point? How do you do it? |
I render everything using OpenGL, so it's either WebGL on the web, EGL on Android and MetalANGLE on iOS. Every OpenGL call is made though some platform-independant interface which has implementation over WebGL and EGL. Entire GUI is rendered by home-grown UI framework. |
Ok, but I don't have your framework, which if I understand correctly is your own private and not shared. If I want to build a web application from scratch with TeaVM using what is publicly available, what tools do I have to build the GUI? This was the point of my previous question. My HTML page is all here:
Everything else I want to do with TeaVM. Here the |
There's a lot of choice. Of course, you can try to proceed with some JS framework (like React) to build UI and try to use TeaVM only to expose business logic. However, you should remember, that directly calling Java from JS and back is not possible, so you end up with wrappers and annotations. If interaction layer between Java and JS is limited, then it would be a working solution. Another way is to do everything from Java. If you are ok to deal with raw DOM or you are ready to invent your own Java framework, then this would be a working solution. You can also try to find something, may be someone already created and published any Java framework for front-end development. For example, you can take a looks at following:
Otherwise, TeaVM is not for you. Despite I'd like to develop TeaVM ecosystem, I simply have no resources for it, so what I can do is to maintain compiler and to hope that someday someone implements a popular web framework on top of TeaVM. |
Thanks for the explanation and for your TeaVM project. Even maintaining a compiler from Java to Javascript is a big effort. Your project seems to be a great help for Java fans. I will try to experiment with TeaVM by directly manipulating the raw DOM with the classes in the org.teavm.jso.dom.html package. |
I managed to create a nice and fully functional web application with TeaVM. Compiling from Java to JavaScript works great! For the graphics I manipulated the DOM directly from Java. It is not clear to me what the WebAssembly compiling and especially the C compiling are for. Could you please give me an explanation? |
It means literally: compile Java bytecode to WebAssembly and C. As for C I need some explanation. It can be used as a ultra-lightweight subset of GraalVM Native Image. The goal is to support platforms where it's hard to get into with LLVM. One may say that LLVM is supported everywhere, but it's not. It was for one project that we wanted to launch as WinRT/UWP application, and nobody could either patch OpenJDK to run as a WinRT app or to make RoboVM run under WinRT (and GraalVM Native Image was too fresh and unstable then). It turned out that for me it was easier to create C BE for TeaVM (especially, when there was WebAssembly BE that already implemented 99% of runtime magic, including GC) rather that for guys who tried alternative approaches. We managed to successfully compile our app (500KLOC of Java code) as a UWP app, but then the project was cancelled due to non-technical reasons. But C backend for TeaVM is still there and usable, because there was just no reason to drop it. This example, in addition to JS and WebAssembly can also target Linux (GTK) |
Thank you for your explanation. 500KLOC of Java code... wow! |
I have tried to read the documentation, but I do not understand which Java APIs I can and cannot use.
For example, I understood that Java FX and Swing are not supported, but I can create my web application graphics using org.teavm.jso.dom.html.HTMLButtonElement, org.teavm.jso.dom.html.HTMLDocument, and org.teavm.jso.dom.html.HTMLElement.
However, I could not find the relevant Javadocs.
In practice, I have to play with HTML elements and CSS styles for the graphical part, while Java is mainly useful for the client business logic. Please correct me if I am wrong.
Having said that, how do I know which standard Java classes to use?
The text was updated successfully, but these errors were encountered: