将 Java 转换为 JavaScript 项目的可行性如何?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18935140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How feasible is it to convert a Java to JavaScript project?
提问by Jeremy
I have a project I maintain in Java that runs primarily as an applet. I am finding that Applets are simply unpractical and dangerous for browser games as most end-users ignorantly trust any applet because it runs in the browser (this is also what gives applets such a terrible reputation.)
我有一个用 Java 维护的项目,它主要作为小程序运行。我发现小程序对于浏览器游戏来说是不切实际和危险的,因为大多数最终用户无知地信任任何小程序,因为它在浏览器中运行(这也是小程序声名狼藉的原因。)
I want to compile my Java project to JavaScript and use HTML5 for rendering. There are a couple problems I can see with this though...
我想将我的 Java 项目编译为 JavaScript 并使用 HTML5 进行渲染。不过,我可以看到一些问题......
Would it be feasible to translate Java reflection to JavaScript? I use Java's ScriptEngine module to run scripts in the engine.
How scalable is this idea of compiling to JavaScript. I have several pure Java dependencies that would also need to be compile to javascript (Specifically an Vorbis Audio SPI.) The code-base compiles to ~300kb (not sure if that helps gauge the size)
What are some other likely restrictions to encounter with this process?
将 Java 反射转换为 JavaScript 是否可行?我使用 Java 的 ScriptEngine 模块在引擎中运行脚本。
这种编译为 JavaScript 的想法的可扩展性如何。我有几个纯 Java 依赖项,它们也需要编译为 javascript(特别是 Vorbis Audio SPI。)代码库编译为 ~300kb(不确定这是否有助于衡量大小)
在这个过程中遇到的其他一些可能的限制是什么?
Thanks.
谢谢。
采纳答案by lastboy
Hmm.. GWT compiles java to JavaScript you can use it.
嗯.. GWT 将 java 编译为 JavaScript,您可以使用它。
Another possibility would be using Rhino
另一种可能性是使用Rhino
Or just expose REST services and create an HTML5 web application using it.
或者只是公开 REST 服务并使用它创建一个 HTML5 Web 应用程序。
Edit: BTW search in the forum. I found some questions like this one.
编辑:BTW 在论坛中搜索。我发现了一些这样的问题。
回答by Flight Odyssey
I found this tool called PlayNwhich may be what you're looking for. I've never used it before, but it looks promising. Of course, it may require rewriting your Java source to use their API, which means, as others have said, you're probably best off just manually porting to JavaScript.
我找到了这个名为PlayN 的工具,这可能正是您要找的。我以前从未使用过它,但看起来很有希望。当然,它可能需要重写您的 Java 源代码以使用它们的 API,这意味着,正如其他人所说,您最好手动移植到 JavaScript。