JNLP is supposed to be the latest and greatest in the Java Applet world post 1.6 release! Personally, I was never a great fan of Applets. I have always felt that Applets are a pain in the wrong place. Inherently difficult and cumbersome to use and deploy.
But some of these concerns have been addressed with the deployJava javascript API. For example, it is now possible to ask the users to automatically install Java plugin or upgrade to a higher version with no extra effort on part of the developer. Java realised this quite late in the game that its very important to make it as user friendly as possible.
Anyway, enough of ranting :), lets outline the steps one by one.
An applet is any class which extends the javax.swing.JApplet. A typical applet is shown below:
public class MyApplet extends JApplet {
@Override
public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
getContentPane().add(new MyPanel(), BorderLayout.CENTER);
}
});
} catch (InvocationTargetException | InterruptedException e) {
e.printStackTrace();
}
}
}
Note that the initialization code which actually adds components to the contentPane should be included in the init() method.
Its recommended that we create the following entries in the Jar's Manifest file:
Application-Name: CountDownLatchDemo
Permissions: sandbox
Codebase: palashray.com
The first parameter is the name of the application. The second is the kind of permission that the Applet needs to run. And the third is the domain name from where the Applet will be hosted. Please refer to this for details.
This can either be achieved by manually creating the jar and specifying the manifest file with the m option:
jar -cvmf my_manifest_file.txt myjar.jar
Or it can be done elegantly with Maven. This is the sample pom.xml:
org.apache.maven.plugins
maven-jar-plugin
2.4
sandbox
palashray.com
CountDownLatchDemo
We need to sign the Jar that has been created above. You can refer to my earlier blog here.
CountDownLatchDemo
Palash Ray
Please note that this jnlp file should be accessible by: http://palashray.com/abc/xyz/def.jnlp
And the my.jar and def.jnlp should be in the same directory.
Since we are invoking the applet through the deployJava API, the user will be prompted for installing or upgrading the java plugin in the browser.
For more information, please refer to this url.