MattPayne.org

Omaha, NE – Computer Programmer

Archive for the 'Java' Category

All things in the universe of java programming and programming that uses the JVM.

Java Web Start Quick Start

Posted by Payne on 13th March 2005

This is still draft -- transitioning to wordpress.... All the files associated with this page are here: demo.zip. Java Web Start installs as part of standard java these days. There are lots of applications available as java web start applications. Any java program that can be launched using the command "java -jar someapp.jar" can be java web started. Also, if you're double clicking on a jar to run the program you can java web start it. There are several advantages to doing this:
  1. Java Web Start always checks for the latest version of your program.
  2. If you want to keep the old version, just create a new URL. The programs are versioned per URL.
  3. The program is only downloaded to the client computer once. After that, startup is very fast. You can even have the program run offline.
Try the java web start of this simple application. Java web start runs by sending the application/x-java-jnlp-file mime type to the browser. The browser then starts the local java web start manager (that was installed as part of standard java); the java web start manager reads the JNLP file (java network launching protocol) and uses this information to download and start the application.

Sending the MIME type to the browser

http://webstartfaq.com/ search for htaccess. There are two tips there: one setting a .htaccess file and the other mixing in a little PHP into the JNLP file. Below is the PHP script I've had luck with.
1   2  header('Content-Type: application/x-java-jnlp-file'); 3  $fn='/home/payne/public_html/demo/demo.jnlp'; 4  fpassthru(fopen($fn,'r')); 5  ?> 

The JNLP file

The next step is to adjust the JNLP (java native launching protocol) file. (here's a copy of the file below (hint use wget)) Here's the breakdown of the line numbers:
  • 4 - the url that this is coming from
  • 5 - the name of this jnlp file
  • 7,8,and 9 are free text set them to anything you like
  • 15 - names the jar with your .class files and other goodies in it. Don't forget that you can read images, properties files, and other stuff directly from a jar. You can have multiple jar tags if you have lots of library jars.
  • 17 - Names the full name of the class to run
  • 18 - Use this if you want your app to have all the privs of someone typing java -jar demo.jar; this requires signing the jar file.
 1  xml version="1.0" encoding="utf-8"?>  2  3  <jnlp spec="0.2 1.0"  4        codebase="http://java.ist.unomaha.edu/~payne/demo"  5        href="demo.jnlp">  6     <information>  7        <title>demo  8        <vendor>Nice to put a homepage URL here   9        <description>This description may be long. 10         11        <offline-allowed/> 12      13     <resources> 14        <j2se version="1.3+ 1.2+"/> 15        <jar href="demo.jar" main="true" download="eager"/> 16      17     <application-desc main-class="edu.unomaha.demo.Demo"/> 18     <security> <all-permissions/>  19   

Signing JAR files with ant

If you need to setup ant on a unix box (and you're running bash) You will also need to add these lines to your ./bash_profile
export JAVA_HOME=/usr/java/j2sdk1.4.1_01 # may have diff value for you export ANT_HOME=/usr/java/ant export PATH=${JAVA_HOME}/bin:${ANT_HOME}/bin:${PATH} 
This ant file signs all the jar files in the current directory. Just type the command "ant" and the files will be digitally signed. It's best to do a "ls -l *.jar;ant;ls -l *.jar" and notice that they are all a bit larger.
xml version="1.0"?> <project default="signit" basedir=".">   <target name="createkey">   <genkey alias="autosigner" keystore="local.keystore"      storepass="atLeastSixChars">     <dname>       <param name="CN" value="autosigner"/>       <param name="OU" value="Joe Blow"/>       <param name="O" value="Joe"/>       <param name="C" value="US"/>     dname>   genkey> target>   <target name="signit" depends="createkey">   <signjar jar="demo.jar"     alias="autosigner" keystore="local.keystore" storepass="atLeastSixChars"     verbose="true">     -- sign all jars in the current working directory. -->     <fileset dir="."><include name="*.jar"/>fileset>   signjar> target>  project>  

Posted in JNLP, Notes | No Comments »