Search code examples
javaopenglservletsawtjava-web-start

Can we embed a stand alone Java game into a webpage?


I'm new to Java development and my requirement is to create a Java game that I need to run on a web server (eg. tomcat) not on client machine. Can I first develop a stand alone Java game and then embed it into a webpage using servlet?


Solution

  • If it is Java based, it can either be embedded in a web page (applet) or launched from a web page.

    It should be possible with this code:

    <APPLET ARCHIVE="jar.jar"CODE="class.class" WIDTH=400 HEIGHT=200></APPLET>
    

    Width/height: The measurements (in pixels) of the window.

    jar.jar: your Jar (Export your project as one)

    class.class: your main class