How to Cross-Compile Java Source Code to JavaScript?

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

    Here's two other options, things to look into and a third option not converting, just living together.

    1. Java2Javascript

    I have been wanting to try this out -- Looks closer to what's been asked. Quoting the web page:

    an Eclipse Java to JavaScript compiler plugin and an implementation of JavaScript version of Eclipse Standard Widget Toolkit (SWT) with other common utilities, such as java.lang.* and java.util.*. You can convert your SWT-base Rich Client Platform (RCP) into Rich Internet Application (RIA) by Java2Script Pacemaker.

    A limited Java in Javascript experience - You'd need to port your necessary dependencies or find alternatives via tools like jQuery, etc.

    1. DukeScript

    As I view DukeScript, it compiles some front-end Javascript and calls Java behind, from the browser's Javascript. It seems more or less a hybrid approach so you can use the Java wealth of libraries from Javascript. I will fall foul of a browser security policy for Java.

    A more full-Javascript on Java experience leveraging the Java-runtime. If I wanted that outside the browser environment I'd use Javascript on Java.

    1. Nashhorn

    Consider this as an example of using Java's resources as foundation for Javascript: Nashorn and JavaFX, as an example for a rich Javascript operated client. Anyway with a Javascript engine inside Java you're not needing to translate between a Javascript-VM to object-code to a Java-VM quite so much.

提交回复
热议问题