Closed vonwenckstern closed 6 years ago
This is our jar file: https://github.com/EmbeddedMontiArc/OCL/blob/master/OCLCDTool/ocl-0.0.8-SNAPSHOT-jar-with-dependencies.jar
And we already tried TeaVM and CheerpJ; both did not work yet.
Thank you for your interests in Bytecoder!
Bytecoder is based on static code analysis to transpile JVM Bytecode into other languages such as JavaScript or WebAssembly. Due to the nature of this analysis it cannot support reflection and dynamic class loading happening at runtime. In consequence Bytecoder does not support reflection based code and other technologies based on it such as scripting languages for the JVM which are evaluated at runtime.
Bytecoder in its core does not support frontend technologies "out-of-the-box". Bytecoder can import functionalities from other ES6-Modules, but it can not directly interact with the DOM or the browser console. So if you want to compile an application into JavaScript, you have to divide it into some kind of hexagonal architecture with a core system and a user interaction system. The core system can be compiled directly into JavaScript. The user interaction system has to be provided at runtime as an ES6 module, which is than linked with the core system to make the system runable.
A great example of this is hosted at https://github.com/mirkosertic/GameComposer. It is a game engine with a JavaFX based editor and a browser-based runtime environment. Both share the same code base written in Java. The modules are separated hexagonal style as described above.
So unfortunately, the answer to your question is no, at least at the moment. Bytecoder cannot transpile your tool without modifications.
Thank you for your detailed answer. I just got some kind of related questions to your project:
If we do not use reflection (let's assume we only want to use the front-end part of our tool), can your tool transpile all kinds of byte code.
Or does it work similar to TeaVM where only java classes are supported which are modelled seperately as the TArrays
class in https://github.com/konsoletyper/teavm/tree/master/classlib/src/main/java/org/teavm/classlib/java/util
And does your tool support UTF-8 encoded strings?
Because if this is the case, one of my students would try to transpile only a part our tool with your ByteCodeToJSTranspiler.
Well, all transpiler frameworks including GWT, TeaVM, Cheerp or Bytecoder must provide a runtime environment. This environment includes core classes such as String, Double, Array, StringBuffer etc and also glue code for memory management and garbage collection. There are the classes you have seen with the T-Prefix. As far as I know, TeaVM and CheerpJ include a very complete set of the JRE classes. Bytecoder includes only a subset, as this project is very young. UTF-8 support is planned, but currently under development.
I would be really glad if Bytecoder would we used elsewhere, but I also inderstand that you need a tool to get the Job done. If you are planning to transpile full Java Applications including Swing components, you should give CheerpJ a try. TeaVM and Bytecoder currently focus on the logic part, and not the UI layer.
Thank you for the clear, nice, and honest explanation.
Does your tool supports it? And how do I translate a complete JAR and launch it later in HTML, so that the console output will be visible?