views:

1404

answers:

5

How do i deploy a java applet for modern browsers? I know there are somehow 3 possibilities but nobody tells me which one to prefer and how to use them.

Does somebody have any resources on that? i cant find any :(

+6  A: 

There is a section in The Java Tutorials titled Deploying Applets which addressed the issue.

From the General Deployment Considerations:

Deploying Applets on the Internet Versus an Intranet

When deploying applets:

  • Use the applet tag if the Web page is accessed through the Internet.
  • Use the object or embed tag if the Web page is accessed through an Intranet.

Deploying Applets for Specific Browsers

When deploying applets:

  • For Internet Explorer only, use the object tag.
  • For the Mozilla family of browsers only, use the embed tag.

If you must deploy an applet in a mixed-browser environment, follow the guidelines in the section Deploying Applets in a Mixed-Browser Environment.

It should be noted that the applet tag has been deprecated, so it's probably not desirable to use that tag. (More information on the applet tag from the W3C)

(Note: Links have been updated from the previous edit to link to The Java Tutorials.)

coobird
thanks for that info. dont know why i didnt find that...
Michael Siebert
+8  A: 

If you have the luxury of targeting Java 6 update 10 or better, you can simplify your life:

<script src="http://java.com/js/deployJava.js"&gt;&lt;/script&gt;
<script>
    var attributes = {codebase:'http://java.sun.com/products/plugin/1.5.0/demos/jfc/Java2D',
                      code:'java2d.Java2DemoApplet.class',
                      archive:'Java2Demo.jar',
                      width:710, height:540} ;
    var parameters = {fontSize:16} ;
    var version = '1.6' ;
    deployJava.runApplet(attributes, parameters, version);
</script>
Robert Munteanu
Can't deployJava.js deploy applets for older Java versions too?
David Underhill
+1  A: 

You might consider using Java Web Start instead of an applet if you are making an application. Applets are used only if are creating something that has to be shown in a browser.

Dev er dev
unfortunately, i'll have to use an applet, because i need it to encrypt/decrypt data from an ajax call (which would also work in javascript, but ie is daaaaamn slow) so we decided to use an applet for that
Michael Siebert
+4  A: 

Use deployJava.js -- even if you AREN'T targeting only 1.6 and above. I've been using it for more than a year, with applets that still support even the MSJVM (Java 1.1).

There are plenty of features that aren't available in the script for older JREs, but it's still quite useful!

Rob Whelan
+1  A: 

Well, be aware that deployJava.js is designed to be called at document load time. So if you insert applet dynamically, upon an event, after DOM has been constructed, you're kinda out of luck with this new standard approach. We had to use the object/embed/noembed construct.

Edit: Oh, someone found a better way for this, but this required manual altering of SUN's original deployJava.js, please see the link below: Java Plug-In - Important addition to deployJava.js

Anton S. Kraievoy
today, I had exactly the same problem. And... yeah.. I really thought about that, too, but some odd feeling in my guts tells me that this is not the correct thing to do...PLUS: deployJava.js is minified and I really don't want to de-minify it by hand (are there any tools?)Perhabs someone should do this, fix deployJava and put it on Github...
Michael Siebert
See the human readable version of the Deployment Toolkit here:http://www.java.com/js/deployJava.txt
Anton S. Kraievoy