I am relatively new to Java and have a Java application consisting of a couple of packages and a number of classes. I want to be able to run this application in a web browser. How do I go about doing this?
5 Answers
Java Web Start is a good technology for deploying Java applications over the web. You can start the application from a web page link, although the application runs outside of the web browser frame: Java Web Start Tutorial.
Java applets allow you to embed a Java application in a web page. It has some serious drawbacks for larger applications.
Servlets (and Java Server Pages) are appropriate technologies for server-side generation of web pages (and other web content) but these technologies won't help you to deploy an existing Swing-based Java application, unless you are prepared to replace the user interface.

- 7,499
- 3
- 32
- 50
-
The applet technology is the only one running the code "in" the browser. – Thorbjørn Ravn Andersen Feb 14 '10 at 17:54
-
+1 Correct and comprehensive answer. Especially because it provides the necessary context (which the original question didn't ask for, but probably needs). – sleske Feb 14 '10 at 19:44
See the section of the Java Tutorial on how to build and deploy applets.

- 398,947
- 96
- 818
- 769
-
3Applets no longer have any relevance other than academic. I.E. No-one outside of scholastic tutorials should be using them, so if this is a non-academic endevour then rather look into web-start or even better gwt. – crowne Feb 14 '10 at 19:28
-
1@crowne: That's a bit extreme. While applets have declined, there are still quite a few useful applets out there, and the Java plugin has improved a lot. I see no reason to discount applets as a deployment option out-of-hand. – sleske Feb 14 '10 at 19:43
-
-
2@sleske: given the capabilities and growth that are available in ajax and html5, you would be doing yourself a disservice by adopting a dying platform such as applets for any new work. Even if you can run new JavaFX applications as applets, you would probably be better off using an adobe front-end and java back-end, although the html5 progress will be eating into adobe's market share too, note their ongoing spat with lack of support from Apple. – crowne Feb 14 '10 at 20:44
-
@crowne, that's quite subjective. Do you have any data to support your evidence that applets are dying? There's been a lot of changes recently which has got applets back on track IMO, and Java penetration is on the rise. – Pool Feb 15 '10 at 13:36
-
@The Feast: there's a fair amount of similar opinion on this thread http://stackoverflow.com/questions/377593/javafx-is-now-out-are-applets-and-java-desktop-officially-dead-dying And I also recall the same sentiment being expressed in a textbook published in 2002 ISBN 9780321210739, although they then went on to use applets for the purpose of teaching java and OO. – crowne Feb 15 '10 at 21:23
-
@crowne, thanks, I've seen a lot of people subjectively dismissing them on here - but I think it's mostly due to the legacy of poor VM's in the past, things have changed a lot in the last few years (see a summary http://stackoverflow.com/questions/580995/why-do-applets-have-such-a-low-adoption-level/598419#598419 ). I guess a bad legacy is real tough to shift - after all people still come out with a generic "Java is slow" and mean it seriously. – Pool Feb 15 '10 at 22:19
I've written some kind of JVM which precompiles Java classes to native JavaScript. Here is an HelloWorld example which runs java programm in the browser:
https://github.com/neo-expert/jsjvm_helloworld
it has also a WebGL demo which renders a 3D cube.

- 465
- 1
- 10
- 20
The easiest way for you will be to use a servlet. What you need:
- Apache Tomcat (Or any other Servlet container)
- Knowledge of what a servlet is (basically a class that extends from servlet, like httpservlet)

- 194
- 2
- 9
-
2In this case the Java code is running on the server rather than in the web browser. – Dan Dyer Feb 14 '10 at 16:59