<?xml version="1.0"?><rss version="2.0">
<channel>
  <title>Alan&#039;s Ramblings - webstart tag</title>
  <link>http://bleaklow.com:80/tags/webstart/</link>
  <description>My opinions may be incorrect, but they are my own</description>
  <language>en</language>
  <copyright>Alan Burlison</copyright>
  <lastBuildDate>Wed, 29 Feb 2012 20:50:00 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  <image>
    <url>http://bleaklow.com/images/misc/logo.gif</url>
    <title>Alan&#039;s Ramblings</title>
    <link>http://bleaklow.com:80/</link>
  </image>
  <item>
    <title>Netbeans, JNI, Webstart and Apache</title>
    <link>http://bleaklow.com:80/2006/06/28/netbeans_jni_webstart_and_apache.html</link>
    <description>
          &lt;p&gt;
Although NetBeans has a Webstart module, it isn&#039;t really up to snuff yet, as I detailed in a &lt;a href=&#034;http://blogs.sun.com/roller/page/alanbur?entry=why_i_hate_xml_and&#034;&gt;previous post&lt;/a&gt;.  Specifically, it doesn&#039;t support JNI code, and it can&#039;t sign the JAR files, which is needed if you have any JNI code to deploy.  However, it&#039;s possible to add the necessary goop to the Netbeans &lt;code&gt;build.xml&lt;/code&gt; file to automate this, with the help of a couple of short scripts.  In addition, we can compress the JAR files using &lt;a href=&#034;http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/pack200.html&#034;&gt;pack200&lt;/a&gt;  - this can give &lt;strong&gt;really&lt;/strong&gt; impressive results, for example it compresses the Matisse &lt;code&gt;swing-layout-1.0.2.jar&lt;/code&gt; file down from 155Kb down to just 19Kb!  The final flourish is to get the build process to generate the Apache configuration files needed to serve Webstart files correctly.  The examples below are all Win32-based as that&#039;s the environment my application works in, but they are trivially convertable to *nix versions.
&lt;p&gt;
The first step is to create a self-signed certificate if you don&#039;t have a proper one, the steps for doing this are described in the &lt;a href=&#034;http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/keytool.html&#034;&gt;keytool&lt;/a&gt; documentation - you need to first create the certificate using the &lt;code&gt;-genkey&lt;/code&gt; option, then sign it with the &lt;code&gt;-selfcert&lt;/code&gt; option.
&lt;p&gt;
Next, we need to add some extra properties into the &lt;code&gt;nbproject/project.properties.file&lt;/code&gt; file to describe the key file and the directories we will use for the webstart build, you should edit these to reflect your setup:
&lt;p&gt;
&lt;pre&gt;
# Properties needed for signing JAR files
webstart.src.dir=webstart_src
webstart.dist.dir=webstart_dist
key.alias=bleaklow.com
keystore.location=d:/shared/bleaklow.keys
keystore.password=password
&lt;/pre&gt;
&lt;p&gt;
We also need a couple of helper scripts - you should put these in the &lt;code&gt;nbprojects&lt;/code&gt; directory:
&lt;p&gt;
&lt;b&gt;signpack.bat&lt;/b&gt;
&lt;pre&gt;
@echo off
REM compress and sign a JAR file, remove the original
REM args are &amp;lt;JAR&amp;gt; &amp;lt;keystore&amp;gt; &amp;lt;password&amp;gt; &amp;lt;alias&amp;gt;
pack200 --repack --no-keep-file-order --strip-debug %1
jarsigner -keystore %2 -storepass %3 %1 %4
pack200 --effort=9 %1.pack.gz %1
del %1
&lt;/pre&gt;
&lt;p&gt;
This script will pack the supplied JAR file using the pack200 utility, and will then sign it with the supplied key.  The &lt;code&gt;--repack&lt;/code&gt; dance is necessary because packing a file with pack200 may change the order of the contents of the file and if it was signed this would break the signing, so we need to pack it, unpack it, then sign it and finally repack it again.
&lt;p&gt;
&lt;b&gt;genvar.bat&lt;/b&gt;
&lt;pre&gt;
@echo off
REM generate a type mapping file for Apache
REM arguments are &amp;lt;JAR&amp;gt;
echo URI: packed/%1.pack.gz&amp;gt;%1.var
echo Content-Type: application/x-java-archive&amp;gt;&amp;gt;%1.var
echo Content-Encoding: pack200-gzip&amp;gt;&amp;gt;%1.var
echo.&amp;gt;&amp;gt;%1.var
echo URI: unpacked/%1&amp;gt;&amp;gt;%1.var
echo Content-Type: application/x-java-archive&amp;gt;&amp;gt;%1.var
&lt;/pre&gt;
&lt;p&gt;
This script generates the type mapping file needed to get Apache to serve either the normal unpacked versions or the packed versions of the files we are going to deploy.  The layout of the generated file needs to be exact, down to each whitespace - if you want to understand this in detail see the &lt;a href=&#034;http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/pack200.html&#034;&gt;pack200 deployment guide&lt;/a&gt; and the Apache documentation for &lt;a href=&#034;http://httpd.apache.org/docs/1.3/content-negotiation.html&#034;&gt;content negotiation&lt;/a&gt;, but my advice is just to accept that the magic files created by the script work ;-)
&lt;p&gt;
Now we need to create the Apache .htaccess file and the Webstart descriptor (JNLP) file.  Create a new directory - &lt;code&gt;webstart_src&lt;/code&gt; and create the following two files in it:
&lt;p&gt;
&lt;b&gt;.htaccess&lt;/b&gt;
&lt;pre&gt;
AddType application/x-java-jnlp-file .jnlp
AddType application/x-java-archive .jar
AddHandler application/x-type-map .var
Options +MultiViews
&amp;lt;Files *.pack.gz&amp;gt;
    AddEncoding pack200-gzip .jar
    RemoveEncoding .gz
&amp;lt;/Files&amp;gt;
&lt;/pre&gt;
&lt;p&gt;
This assumes that your webserver &lt;code&gt;httpd.conf&lt;/code&gt; is set up to allow the .htaccess file to function, if not see the &lt;a href=&#034;http://httpd.apache.org/docs/1.3/howto/htaccess.html&#034;&gt;Apache docs&lt;/a&gt; for how to do this.  This file sets up the MIME types for the Webstart files we are going to serve, and establishes the content negotiation mechanism needed to serve the packed versions.
&lt;p&gt;
&lt;b&gt;OziGeocacheUK.jnlp&lt;/b&gt;
&lt;pre&gt;
&amp;lt;?xml version=&#034;1.0&#034; encoding=&#034;UTF-8&#034;?&amp;gt;
&amp;lt;!DOCTYPE jnlp PUBLIC &#034;-//Sun Microsystems, Inc.//DTD JNLP 1.5//EN&#034;
  &#034;http://www.netbeans.org/jnlp/DTD/jnlp.dtd&#034;&amp;gt;
&amp;lt;jnlp spec=&#034;1.0+&#034;
 codebase=&#034;http://oziapi-java.sourceforge.net/OziGeocacheUK&#034;
 href=&#034;OziGeocacheUK.jnlp&#034;&amp;gt;
  &amp;lt;information&amp;gt;
    &amp;lt;title&amp;gt;OziGeocacheUK&amp;lt;/title&amp;gt;
    &amp;lt;vendor&amp;gt;bleaklow.com&amp;lt;/vendor&amp;gt;
    &amp;lt;homepage href=&#034;http://oziapi-java.sourceforge.net/OziGeocacheUK&#034;/&amp;gt;
    &amp;lt;description&amp;gt;GeocacheUK access for OziExplorer&amp;lt;/description&amp;gt;
    &amp;lt;icon href=&#034;logo64.gif&#034; kind=&#034;splash&#034;/&amp;gt;
    &amp;lt;icon href=&#034;logo32.gif&#034;/&amp;gt;
    &amp;lt;offline-allowed/&amp;gt;
    &amp;lt;shortcut&amp;gt;
      &amp;lt;desktop/&amp;gt;
    &amp;lt;/shortcut&amp;gt;
  &amp;lt;/information&amp;gt;
  &amp;lt;security&amp;gt;
     &amp;lt;all-permissions/&amp;gt;
  &amp;lt;/security&amp;gt;
  &amp;lt;resources os=&#034;Windows&#034;&amp;gt;
    &amp;lt;j2se version=&#034;1.5+&#034; href=&#034;http://java.sun.com/products/autodl/j2se&#034;/&amp;gt;
    &amp;lt;jar href=&#034;OziGeocacheUK.jar&#034;/&amp;gt;
    &amp;lt;jar href=&#034;OziAPI.jar&#034;/&amp;gt;
    &amp;lt;jar href=&#034;swing-layout-1.0.1.jar&#034;/&amp;gt;
    &amp;lt;nativelib href=&#034;OziAPINative.jar&#034;/&amp;gt;
  &amp;lt;/resources&amp;gt;
  &amp;lt;application-desc main-class=&#034;com.bleaklow.ozigeocacheuk.Main&#034;/&amp;gt;
&amp;lt;/jnlp&amp;gt;
&lt;/pre&gt;
&lt;p&gt;
You should name this file appropriately for your project - in my case the Netbeans project is called OziGeocacheUK.  Obviously this file will need modifying to suit your particular project - the format of  JNLP files is documented &lt;a href=&#034;http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/syntax.html&#034;&gt;here&lt;/a&gt;, but I&#039;ll point out the most important bits:
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;offline_allowed&lt;/b&gt;&lt;br /&gt;
Java Web Start will also check to see if an update is available. However, if the application is already downloaded the check will timeout after a few seconds, in which case the cached application will be launched instead.
&lt;li&gt;&lt;b&gt;security/all-permissions&lt;/b&gt;&lt;br /&gt;
The application will have full access to the client machine and local network. If an application requests full access, then all JAR files must be signed.
&lt;/ul&gt;
&lt;p&gt;
In my directory I also have two icon files, &lt;code&gt;icon32.gif&lt;/code&gt; and &lt;code&gt;icon64.gif&lt;/code&gt; which are 32x32 and 64x64 pixel icon files that I use with my application.  If you do have these files, they must be GIF format, Webstart doesn&#039;t support PNG.
&lt;p&gt;
The final step is to add an Ant target to build a Webstart-deployable file tree to your &lt;code&gt;build.xml&lt;/code&gt; file, the following should be fairly self-explanatory:
&lt;p&gt;
&lt;pre&gt;
&amp;lt;!-- Create a webstart tree --&amp;gt;
&amp;lt;target name=&#034;build-webstart&#034; depends=&#034;init,compile&#034;
  description=&#034;Build a webstart version&#034;&amp;gt;
    &amp;lt;!-- 1. Create a fresh webstart directory --&amp;gt;
    &amp;lt;delete dir=&#034;${webstart.dist.dir}&#034;/&amp;gt;
    &amp;lt;mkdir dir=&#034;${webstart.dist.dir}/unpacked&#034;/&amp;gt;
    &amp;lt;mkdir dir=&#034;${webstart.dist.dir}/packed&#034;/&amp;gt;

    &amp;lt;!-- 2. Copy the source files --&amp;gt;
    &amp;lt;copy todir=&#034;${webstart.dist.dir}&#034;&amp;gt;
        &amp;lt;fileset dir=&#034;${webstart.src.dir}&#034;/&amp;gt;
    &amp;lt;/copy&amp;gt;

    &amp;lt;!-- 3. Copy in all the java JAR files --&amp;gt;
    &amp;lt;copy todir=&#034;${webstart.dist.dir}/unpacked&#034; flatten=&#034;true&#034;&amp;gt;
        &amp;lt;fileset dir=&#034;${dist.dir}&#034; includes=&#034;**/*.jar&#034;/&amp;gt;
    &amp;lt;/copy&amp;gt;

    &amp;lt;!-- 4. Create a JAR file from the DLLs --&amp;gt;
    &amp;lt;jar destfile=&#034;${webstart.dist.dir}/unpacked/OziAPINative.jar&#034;
      basedir=&#034;${dist.dir}&#034; includes=&#034;*.dll&#034;/&amp;gt;

    &amp;lt;!-- 5. Create packed and signed versions of the JAR files --&amp;gt;
    &amp;lt;copy todir=&#034;${webstart.dist.dir}/packed&#034;&amp;gt;
        &amp;lt;fileset dir=&#034;${webstart.dist.dir}/unpacked&#034; includes=&#034;*.jar&#034;/&amp;gt;
    &amp;lt;/copy&amp;gt;
    &amp;lt;apply executable=&#034;nbproject/signpack.bat&#034; type=&#034;file&#034;
      resolveexecutable=&#034;true&#034; failonerror=&#034;true&#034; ignoremissing=&#034;false&#034;&amp;gt;
        &amp;lt;fileset dir=&#034;${webstart.dist.dir}/packed&#034; includes=&#034;*.jar&#034;/&amp;gt;
        &amp;lt;srcfile/&amp;gt;
        &amp;lt;arg value=&#034;${keystore.location}&#034;/&amp;gt;
        &amp;lt;arg value=&#034;${keystore.password}&#034;/&amp;gt;
        &amp;lt;arg value=&#034;${key.alias}&#034;/&amp;gt;
    &amp;lt;/apply&amp;gt;

    &amp;lt;!-- 6. Sign all the unpacked JAR files --&amp;gt;
    &amp;lt;signjar
        alias=&#034;${key.alias}&#034;
        keystore=&#034;${keystore.location}&#034;
        storepass=&#034;${keystore.password}&#034; &amp;gt;
        &amp;lt;fileset dir=&#034;${webstart.dist.dir}&#034; includes=&#034;**/*.jar&#034; /&amp;gt;
    &amp;lt;/signjar&amp;gt;

    &amp;lt;!-- 7. Create the Apache type mapping files --&amp;gt;
    &amp;lt;apply executable=&#034;nbproject/genvar.bat&#034; type=&#034;file&#034; relative=&#034;true&#034;
      dir=&#034;${webstart.dist.dir}&#034; dest=&#034;${webstart.dist.dir}&#034;
      resolveexecutable=&#034;true&#034; failonerror=&#034;true&#034; ignoremissing=&#034;false&#034;&amp;gt;
        &amp;lt;fileset dir=&#034;${webstart.dist.dir}/unpacked&#034; includes=&#034;*.jar&#034;/&amp;gt;
        &amp;lt;flattenmapper/&amp;gt;
    &amp;lt;/apply&amp;gt;
    &amp;lt;fixcrlf srcdir=&#034;${webstart.dist.dir}&#034; eol=&#034;lf&#034; eof=&#034;remove&#034;
       includes=&#034;*.var&#034;/&amp;gt;
&amp;lt;/target&amp;gt;
&lt;/pre&gt;
&lt;p&gt;
Running this target in Netbeans produces the following directory tree under the &lt;code&gt;webstart_dist&lt;/code&gt; subdirectory of your Netbeans project:
&lt;p&gt;
&lt;pre&gt;
.htaccess
logo32.gif
logo64.gif
OziGeocacheUK.jnlp
packed\OziAPI.jar.pack.gz
packed\OziAPINative.jar.pack.gz
packed\OziGeocacheUK.jar.pack.gz
packed\swing-layout-1.0.1.jar.pack.gz
unpacked\OziAPI.jar
unpacked\OziAPINative.jar
unpacked\OziGeocacheUK.jar
unpacked\swing-layout-1.0.1.jar
&lt;/pre&gt;
&lt;p&gt;
This tree can then be directly deployed to an Apache webserver as it contains everything needed to serve your application.  I&#039;ll cover how you can get Netbeans to automatically deploy the application in a subsequent post.
&lt;p&gt;</description>
      <category>Web</category>
    <category>Tech</category>
    <category>Java</category>
    <comments>http://bleaklow.com:80/2006/06/28/netbeans_jni_webstart_and_apache.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2006/06/28/netbeans_jni_webstart_and_apache.html</guid>
    <pubDate>Wed, 28 Jun 2006 03:10:35 GMT</pubDate>
  </item>
  <item>
    <title>Why I hate XML, and Ant&#039;s use of it in particular</title>
    <link>http://bleaklow.com:80/2006/03/25/why_i_hate_xml_and_ants_use_of_it_in_particular.html</link>
    <description>
          &lt;p&gt;
I was googling around for examples of how to sign a JAR file in Ant using the signjar task and came across &lt;a href=&#034;http://www.codecomments.com/message630181.html&#034;&gt;this&lt;/a&gt; monstrosity - 217 lines of turgid XML.  How anyone can say Ant is an improvement over make is a mystery to me, and how anyone could ever think that XML is fit for consumption by humans is an even &lt;b&gt;bigger&lt;/b&gt; mystery.  XML is food for machines, not people.  I sincerely hope that the current fad for doing &lt;a href=&#034;http://thedailywtf.com/forums/63360/ShowPost.aspx&#034;&gt;everything in XML&lt;/a&gt; (and we have some examples close to home) is going to an early grave.
&lt;/p&gt;&lt;p&gt;
What I&#039;m actually trying to do is to deploy an application via WebStart from within NetBeans - I&#039;ve loaded up the NetBeans WebStart module but it really doesn&#039;t cut the mustard yet, it doesn&#039;t support JAR signing, it hard-codes the name of the JNLP file and it assumes you want a WAR file building.  Here&#039;s hoping they make the necessary improvements in short order.
&lt;/p&gt;</description>
      <category>Tech</category>
    <category>Java</category>
    <comments>http://bleaklow.com:80/2006/03/25/why_i_hate_xml_and_ants_use_of_it_in_particular.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2006/03/25/why_i_hate_xml_and_ants_use_of_it_in_particular.html</guid>
    <pubDate>Sat, 25 Mar 2006 08:26:49 GMT</pubDate>
  </item>
  </channel>
</rss>

