I am a beginner in java game programming. I have developed a simple java game and obtained a .jar file of it. It is not an applet. I would like to run it on a browser. Is that possible? How can I achieve that?
3 Answers
Assuming your jar's main class simply opens a JFrame to show its contents, you can build a wrapper applet class which simply invokes it, like this:
public class WrapperApplet extends Applet {
public void start() {
new Thread("application main Thread") {
public void run() { runApplication(); }
}.start();
}
private void runApplication() {
my.Application.main(new String[0]);
}
}
If you want it nicer, have the applet show a button and start the main method only after the button is clicked.

- 73,284
- 20
- 146
- 210
It's possible with Java Web Start. From the Wikipedia article:
Web Start can also launch unmodified applets that are packaged inside .jar files, by writing the appropriate JNLP file. This file can also pass the applet parameters. Such applets also run in a separate frame. Applet launcher may not support some specific cases like loading class as resource." The same article mentions some of the problems with applets "Web Start has an advantage over applets in that it overcomes many compatibility problems with browsers' Java plugins and different JVM versions.
This SO question explains some of the tradeoffs on Applets v. JWS... In my opinion, if you expect a lot of people on different types of systems to use your application, or if it uses a fair amount of memory (likely with a game), JWS is better.

- 1
- 1

- 744
- 4
- 17
-
But my game is already there in a .jar file. I am just looking for a way to deploy it and get it running on the browser, as if an applet. – Nader Khan Dec 11 '11 at 16:31
-
It's possible with JWS. From the Wikipedia article: "Web Start can also launch unmodified applets that are packaged inside .jar files, by writing the appropriate JNLP file. This file can also pass the applet parameters. Such applets also run in a separate frame. Applet launcher may not support some specific cases like loading class as resource." The same article mentions some of the problems with applets "Web Start has an advantage over applets in that it overcomes many compatibility problems with browsers' Java plugins and different JVM versions." – Chip McCormick Dec 11 '11 at 18:47
-
This SO question explains some of the tradeoffs on Applets v. JWS: http://stackoverflow.com/questions/2530380/java-web-start-vs-embedded-java-applet In my opinion, if you expect a lot of people on different types of systems to use your application, or if it uses a fair amount of memory (likely with a game), JWS is better. – Chip McCormick Dec 11 '11 at 18:54
-
@ChipMcCormick The asker has a non-applet game, not an applet which should be started as JWS. – Paŭlo Ebermann Dec 11 '11 at 20:10