Some time ago I had to learn to use this definition of the Java platform to develop a small Swing application that would run via Java Web Start from a link in a Web application. To use Java Web Start is required above all make various settings, no programming.
To do this I followed these simple steps.
Steps to enable running from a web application JavaWebStart
1. Package the application
The first thing we do is package your application into a JAR file . In addition, to run our application from an application of JavaWebStart we digitally sign the JAR but this will be explained later. To package your application use the command line tool for Java. But in any case, you can use any tool available in our IDE, if one is available.
\u0026lt;MIAPLICACION_DIR>. \u0026lt;nombre-archivo-jar> Jar-cf. Jar \u0026lt;clase-java1>. \u0026lt;clase-java2> Class ;. \u0026lt;clase-javaN> class. class
2. Digital signature
We have almost finished our JAR, now we just signed. This digital signature is important since all applications run within a sandbox , a client security space in which to run the application. The steps are as follows.
a) Generate Keystore: From command line go to the directory bin of our installation of Java (JAVA_HOME ).
\u0026lt;JAVA_HOME> \\ bin> keytool-genkey-alias test-RSA-keystore keyalg test.jks
Then the file will be generated test.jks in the bin directory .
b) The following will sign the JAR tool keytool available IUI IUI 2.4.1 keytool
With these steps we will have signed a packaged application that can run on the client. For more information about digital signing of listen to the podcast Javahispano not. 080 - Cryptography and Digital Signature .
3. Configuration file Java Web Start
Now create the configuration file of our application Java Web Start in your text editor of choice. The configuration file have the name we want and with the extension. jnlp ( holaMundo.jnlp ). You can find more information on how to create and more configuration options on the following link JNLP File Syntax.
\u0026lt;? Xml version = "1.0" encoding = "UTF-8"?>
\u0026lt;jnlp spec = "1.0 +" codebase =
"http://localhost:8080/ micontextoweb / javaws "
href =" TheTime.jnlp "
>
\u0026lt;! - Overview of our application ->
\u0026lt;information & # 62;
Hello \u0026lt;title> World \u0026lt;/ title>
\u0026lt;vendor> Jorge Ruiz Aquino \u0026lt;/ vendor>
\u0026lt;homepage href="/micontextoweb" />
\u0026lt; ; description> Sample file \u0026lt;/ description>
\u0026lt;/ information>
\u0026lt;offline-allowed/>
\u0026lt;! - Establishes permits for the application in the sandbox ->
\u0026lt;security>
\u0026lt;all-permissions/>
\u0026lt;/ security>
\u0026lt;! -
are listed the resources needed to implement the application,
as the required minimum version of Java, the location of the JAR of our APPLICATION & # 243, n,
addition to the external libraries to be used.
->
\u0026lt;resources>
\u0026lt;j2se version="1.5+" />
\u0026lt;jar href = "http://localhost:8080/ micontextoweb / javaws / AplicacionFirmada.jar "/>
\u0026lt;/ resources>
\u0026lt;! - Set the name of the class containing the method main () ->
\u0026lt;application-desc main-class="ClaseMain" />
\u0026lt;/ jnlp>
permits in our previous settings are needed, along with digital signature that we have added the JAR in the previous step.
Now we have our file AplicacionFirmada.jar and our own JavaWebStart holaMundo.jnlp , will these files and necessary libraries where appropriate within our Web server. In my case, it is on my Web server Apache Tomcat
4. JNLP support in the Web server
The following will ensure that the Web server supports files of type JNLP, which is the extension of the Java Web Start. To this should enable support the MIME type in the server configuration, for example, the Tomcat Web server can be enabled in the configuration file
\u0026lt;mime-mapping>
\u0026lt;extension> jnlp \u0026lt;/ extension>
\u0026lt;mime-type> application/x-java- jnlp-file \u0026lt;/ mime-type>
\u0026lt;/ mime-mapping>
5. JNLP support in the Web browser
mimetypeCheck function ()
{/ / First, determine if
Webstart is available if (navigator.mimeTypes ['application / x-java-jnlp-file']) {
navigator.mimeTypes plugin = ['application / x-java-jnlp-file' ];
} else {document.write ("no association
jnlp file");}
/ / Next, check for Appropriate
family version for (var i = 0; i < navigator.mimeTypes.length; i++) {
plugin = navigator.mimeTypes [i] ;
}}
mimetypeCheck ();
6. Link to Web Start Java Web application
Finally, add a link on our Web application to download the JNLP application.
\u0026lt;a href="http://localhost:8080/micontextoweb/javaws/archivo.jnlp"> Download JNLP \u0026lt;/ a>
We are now ready to start Web server and test the execution of our first application Java Web Start.
luck with your first cup of Java Web Start.