在 Web 浏览器中运行 Java 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2261728/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 05:24:27  来源:igfitidea点击:

Run a Java application in a web browser

javaappletembed

提问by Shanon

I am relatively new to Java and have a Java application consisting of a couple of packages and a number of classes. I want to be able to run this application in a web browser. How do I go about doing this?

我对 Java 比较陌生,有一个 Java 应用程序,它由几个包和许多类组成。我希望能够在 Web 浏览器中运行此应用程序。我该怎么做?

回答by skaffman

See the section of the Java Tutorialon how to build and deploy applets.

请参阅Java 教程中有关如何构建和部署小程序的部分。

回答by Monachus

The easiest way for you will be to use a servlet. What you need:

对您来说最简单的方法是使用 servlet。你需要什么:

  • Apache Tomcat (Or any other Servlet container)
  • Knowledge of what a servlet is (basically a class that extends from servlet, like httpservlet)
  • Apache Tomcat(或任何其他 Servlet 容器)
  • 什么是 servlet 的知识(基本上是从 servlet 扩展的类,如 httpservlet)

回答by richj

Java Web Start is a good technology for deploying Java applications over the web. You can start the application from a web page link, although the application runs outside of the web browser frame: Java Web Start Tutorial.

Java Web Start 是一种在 Web 上部署 Java 应用程序的好技术。您可以从网页链接启动应用程序,尽管应用程序在 Web 浏览器框架之外运行:Java Web Start Tutorial

Java applets allow you to embed a Java application in a web page. It has some serious drawbacks for larger applications.

Java 小程序允许您在网页中嵌入 Java 应用程序。对于较大的应用程序,它有一些严重的缺点。

Servlets (and Java Server Pages) are appropriate technologies for server-side generation of web pages (and other web content) but these technologies won't help you to deploy an existing Swing-based Java application, unless you are prepared to replace the user interface.

Servlet(和 Java 服务器页面)是服务器端生成网页(和其他 Web 内容)的合适技术,但这些技术不会帮助您部署现有的基于 Swing 的 Java 应用程序,除非您准备更换用户界面。

回答by crowne

If you want a really fancy web-browser based application written in java, then you should learn gwt.

如果你想要一个用 java 编写的基于 web 浏览器的非常漂亮的应用程序,那么你应该学习gwt

回答by neoexpert

I've written some kind of JVM which precompiles Java classes to native JavaScript. Here is an HelloWorld example which runs java programm in the browser:

我已经编写了某种 JVM,它将 Java 类预编译为原生 JavaScript。这是一个在浏览器中运行 java 程序的 HelloWorld 示例:

https://github.com/neo-expert/jsjvm_helloworld

https://github.com/neo-expert/jsjvm_helloworld

it has also a WebGL demo which renders a 3D cube.

它还有一个 WebGL 演示,用于渲染 3D 立方体。