How to Cross-Compile Java Source Code to JavaScript?

后端 未结 7 1483
醉酒成梦
醉酒成梦 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:39

    When you use GWT, you're basically converting the UI portion into Javascript (and it assumes that you use the UI widgets provided when you write your Java). Only some of the Java libraries are accessible within Javascript. Typically in a GWT application anything that makes heavy use of Java libraries would run on the server side and connect to the Javascript as AJAX (which GWT handles for you). So GWT isn't necessarily converting your full application into Javascript (though it can if you're willing to limit your use of Java libraries and some functionality).

    At any rate, if this approach (calling out to Java running on a server from within Javascript) appeals to you, one nice option is DWR, which basically allows your Javascript to directly call methods in Java classes running on the server (without you having to build a web service or other frontend). Not what you asked, I know.

    More relevantly, it looks like there's source code for a sample app demonstrating the use of gwt-exporter.

提交回复
热议问题