java 借助小程序在网页中运行普通 Jar 文件

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

Run normal Jar file in web page with the help of applet

javahtmldeploymentjarapplet

提问by Ujju

I have a Jar file created in Java which contains external libraries along with class files (to make it more complicated). Our mission is to somehow run this program on web.

我有一个用 Java 创建的 Jar 文件,其中包含外部库和类文件(使其更复杂)。我们的任务是以某种方式在网络上运行这个程序。

Applets are used to run Java on HTML but my problem is my jar is not Applet Jar so I can't include jar in applet tag, so should I rewrite all my java code as applet or is there any simple way as to just convert my jar to applet jar and include on HTML?

Applets 用于在 HTML 上运行 Java,但我的问题是我的 jar 不是 Applet Jar,所以我不能在 applet 标签中包含 jar,所以我应该将我所有的 java 代码重写为 applet 还是有任何简单的方法来转换我的jar 到 applet jar 并包含在 HTML 中?

采纳答案by Andrew Thompson

Launch the frame based app. from a link using Java Web Start.

启动基于框架的应用程序。来自使用Java Web Start的链接。



No it is not frame based, it is actually printer application via serial port connection, so right now im trying to rewrite in applet from scratch

不,它不是基于框架的,它实际上是通过串口连接的打印机应用程序,所以现在我试图从头开始重写小程序

To get it to work on the client-side (easily for the client) will require either an embedded (or free-floating) applet or a free floating frame launched using JWS. Take your pick. Note that unless the code is digitally signed (by you) and trusted (by the end user) it will not be able to print.

为了让它在客户端工作(对客户端来说很容易)将需要一个嵌入式(或自由浮动)小程序或一个使用 JWS 启动的自由浮动框架。随你挑。请注意,除非代码经过数字签名(由您)并受信任(由最终用户),否则它将无法打印。

There is a service available to allow sand-boxed apps. deployed using JWS to print, but it would not be as specific as accessing the serial port, and would require changes to the code.

有一项服务可用于允许沙盒应用程序。使用 JWS 部署进行打印,但它不会像访问串行端口那样具体,并且需要更改代码。



I got a bit confused when you mentioned 'convert' and thought you meant that it was based in a free floating frame. Now you explain it is neither an applet or frame makes something more clear for me.

当您提到“转换”并认为您的意思是它基于自由浮动框架时,我有点困惑。现在你解释说它既不是小程序也不是框架让我更清楚。

..should I rewrite all my java code as applet?

..我应该将我所有的java代码重写为applet吗?

No, of course not. You just add that Jar to the run-time class-path of the applet using the archiveattribute, then call it from the init()or start()(as appropriate) methods of a very simple applet.

不,当然不。您只需使用该archive属性将该 Jar 添加到小程序的运行时类路径,然后从一个非常简单的小程序的init()or start()(视情况而定)方法中调用它。

But I still recommend using JWS for a free floating frame over using an applet. The code for either is easy, but applet deployment is a lot harder.

但我仍然建议使用 JWS 来获得自由浮动框架而不是使用小程序。两者的代码都很简单,但部署小程序要困难得多。

回答by Marius

<applet code="MainClass.class" archive="Applett.jar" width=550 height=400></applet>Take a look here http://www.htmlcodetutorial.com/applets/applets.html

<applet code="MainClass.class" archive="Applett.jar" width=550 height=400></applet>看看这里http://www.htmlcodetutorial.com/applet/applet.html