Search code examples
javawebbrowserapplethosting

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?


Solution

  • 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.