How to Cross-Compile Java Source Code to JavaScript?

后端 未结 7 1469
醉酒成梦
醉酒成梦 2020-12-12 19:02

Given a set of Java source code files, how can I compile them into one or more JavaScript files that can be used with hand-crafted JavaScript?

GWT is one option, but

相关标签:
7条回答
  • 2020-12-12 19:54

    I am not sure if it fits your use case, but if you agree to drop Java APIs and use JavaScript APIs from Java, then you can use JSweet, a Java to JavaScript transpiler built on the top of TypeScript. It gives you access to hundreds of well-typed JavaScript APIs (DOM, jQuery, underscore, angularjs, etc). It generates JavaScript code and you can mix it with legacy JavaScript and TypeScript code.

    Note: JSweet will not work for legacy Java code and legacy Java APIs, but your use case did not mention reusing legacy code.

    [UPDATE] Since version 1.1, JSweet now also supports some Java APIs such as Collections (java.util). So, it is possible to reuse legacy Java code to a certain extent. It is also quite straightforward to add your own support for Java APIs.

    0 讨论(0)
提交回复
热议问题