简体   繁体   中英

What is the recommended way to embed a Java program in a web page?

I have a game in a runnable.jar that works great on my computer, and I want to host it on a web page. I've been scouring the web for the best way to do this but older answers aren't taking into account security concerns that have arisen in the past few years. I know Java Applets aren't supported by most browsers any more, and JWS (Java Web Start) is now deprecated and removed . I've seen some recommendations of OpenWebStart but haven't been able to find many supporting docs or implementation details.

My question is: what is the proper way to host a web page that allows a user to play my Java game in their browser?

Given the demise of Java applets , there is no way to run a Java app within the web browser. Securely integrating a JVM within a web browser proved impractical.

Java Web Start , and the open-source alternative OpenWebStart , do not run a Java app within the browser. They provide for a way for a web browser to conveniently download a Java app to the local client computer, and launch that Java app locally. The Java app runs separately from the web browser, independently.

This app delivery mechanism may be useful in controlled settings such as corporate or educational environments where an IT team controls the client machines. For the general public, Web Start is not likely to be practical because Java is no longer pre-installed on client machines running mainstream operating systems such as macOS, iOS/iPadOS, Windows, Linux, BSD, etc.

For public distribution of your app nowadays, Oracle expects a Java-based app to be bundled with its own JVM, and delivered through mechanisms such as an app store or a downloaded installer. This means you the developer must release an edition for each host platform you choose to support.

New technologies such as the Java Platform Module System , and the jlink & jpackage tools (see relevant Java JEPs), make bundling a JVM easier than ever.

See the Oracle white paper, Java Client Roadmap Update .

Please consider using CheerpJ , our solution to run unmodified Java applications and applets in the browser.

This example shows how to integrate a Java application in the browser.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>CheerpJ test</title>
    <script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
  </head>
  <body>
  </body>
  <script>
      cheerpjInit();
      cheerpjCreateDisplay(800,600);
      cheerpjRunMain("ChangeThisToYourClassName", "/app/my_application_archive.jar:/app/my_dependency_archive.jar"); 
  </script>
</html>

More info can be found here: https://docs.leaningtech.com/cheerpj/Getting-Started

CheerpJ is designed to run 100% of Java applications in the browser, but please note that it does not currently support JNI/binary libraries.

Full disclosure, I am lead developer of CheerpJ and CTO of Leaning Technologies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM