views:

95

answers:

4

Hello,

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?

+2  A: 

See the section of the Java Tutorial on how to build and deploy applets.

skaffman
Applets 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
@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
@crowne: I agree, but I was just answering what was asked.
skaffman
@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
@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
@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
@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
+1  A: 

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)
Monachus
In this case the Java code is running on the server rather than in the web browser.
Dan Dyer
+4  A: 

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.

richj
The applet technology is the only one running the code "in" the browser.
Thorbjørn Ravn Andersen
+1 Correct and comprehensive answer. Especially because it provides the necessary context (which the original question didn't ask for, but probably needs).
sleske
A: 

If you want a really fancy web-browser based application written in java, then you should learn gwt.

crowne