I know how to deploy an applet using applet
, object
, embed
tags and JavaScript
, but I'm after the best approach (in terms of end user experience).
Sun suggests using the applet tag , and a mixed embed / object tag on the same page.
What I am considering is the following:
- Cross-browser support.
- Fallback to download page if incorrect Java version is found (eg pre 1.5).
- Loading page for both Java VM start period and while the Jar is downloaded (ideally a custom splash screen with a progress bar).
Questions have been asked before: how to deploy , check for 1.6 , and Plugin framework . None of these fully answer my question. I am also not considering web start or Java FX.
My current solution is to include an additional small test applet compiled for Java 1.1. If Java pre-1.5 is found it redirects the page to the failure page. If no Java is found the page asks the user to visit java.com. This works acceptably, but is poor because it requires an additional applet and doesn't show anything while the VM is starting.
Source: Tips4all, CCNA FINAL EXAM
See PulpCore's solution (license: BSD).
ReplyDeleteAn example: the Milpa game... now, that's Rolls-Royce applet deployment if I ever saw it.
And -- absolutely agreed, Sun's Deployment Toolkit sorely needs to handle disabled Java -- it seems to ignore that entirely, currently.
After much struggling with old and outdated information all over the web it seems like there's actually a really easy way to deploy applets - just let Sun write the correct tags for you!
ReplyDelete<script src="http://java.com/js/deployJava.js"></script>
<script>
var attributes = {
code:'java2d.Java2DemoApplet.class',
archive:'Java2Demo.jar',
width:710,
height:540
};
var parameters = {
fontSize:16
};
var version = '1.6' ; // whichever minimum version you want to target, null works also
deployJava.runApplet(attributes, parameters, version);
</script>
Worked like a charm, cross-browser, for me, with auto redirection to download page if java's not installed.
More info here:
http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit
I find JavaScript to be the best solution. For IE, write an object tag and control the exact minimum version of the JRE through the classid attribute, for everything else an embed tag with type="application/x-java-applet;version=1.5" works just fine. Both use the built-in browser mechanisms for coping with an out of date (or complete lack of) java.
ReplyDeleteYou can also do fancy things like specify 1.5.0 as the minimum version, but set the auto-download to 1.6 so anyone without java gets the latest JRE instead of 1.5.
The project I work on has rolled our own cross-platform JS wrapper for many years, but with Java 6 update 10 Sun created deployJava.js which aims to solve all of these problems for you.
+1 to pool for applet-fu worked for me on chrome, FF, IE 6,7,8.
ReplyDeleteI don't think it can get more rolls royce than this here:
http://products.metamolecular.com/2009/06/08/better-applet-deployment-with-applet-fu
http://github.com/metamolecular/applet-fu
Seems like an absolutely simple thing, there isn't much documentation either. But thats the beauty!!
applet_fu.run(
{'width':'550','height':'320'},
{
'archive':'myapplet.jar',
'code':'com/example/MyApplet.class',
'foo':'bar'
},
'1.4.2',
'<img src="/no-java.png" />'
);
Yes thats right, you can slap in html to display if the applet isn't found.
The 1.4.2 part is the minimum version to check for, if a lower version is found it will still show no java. foo : bar is an example of params.
For best cross-browser compatibility, you should follow SUn's advice, particularly the use of mixed embed/object tags. It's ugly, but gives you the best coverage.
ReplyDeleteConsider having a small applet on the start page, which tells the browser to go to the real applet page.
ReplyDeleteOn the start page, also have a "You can get Java here" link.
In my experience, nasty javascript gives nasty support :(
Also note that the Java 6 u 10 can use Java WebStart to deploy Applets. This might be a nicer user experience if your users have this version or later.
Hi just use the object tag. It's part of the HTML specification and works with most browsers.
ReplyDeleteThe fallback with installation option is just writing some text in the tag.
Here is a usefull article on the subject:
http://depth-first.com/articles/2008/02/20/demystifying-java-applets-part-1-cross-browser-standards-compliant-pure-html-deployment-using-the-object-tag
Regards
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.
ReplyDeleteWe 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
I would strongly recommend against deployJava.js.
ReplyDeleteI doubt it was tested anywhere.
Just look at its code:
s = '<param name="' + parameter + '" value="' +
parameters[parameter] + '">';
It doesn't close the tag! And Chrome chokes on this completely giving me "Uncaught Error: INVALID_STATE_ERR: DOM Exception 11"! Not to mention the use of document.write which you have to overcome with stuff like this Java Plug-In - Important addition to deployJava.js.
Registered just to tell this, as I spent four hours in complete frustration dealing with this the other day :(