Search code examples
javajarjnlpjava-web-start

How to include jar dependencies in java webstart project


We are trying to develop a printing application using java webstart. We created the jar as a normal jar file using eclipse. Our application needs external libraries for connecting to the database, converting the data to bytes etc.

We were able to do this before by putting the necessary jars in the /ext/ directory of the jre folder. However this caused a library conflict with our tomcat server so we would like to avoid this approach.

We also tried exporting the project as a runnable jar as the needed libraries are already packaged in the jar also. But when trying to run the application it seems that it is not able to see the libraries within the jar.

We also know that we can place the needed libraries in a folder alongside the jar and reference them one by one in the jnlp file. However we would like to avoid this approach as we have a lot of external jars and we do not want to import them one by one :)

So my question is how do we package the java webstart jar properly? Is there another way? What is the best approach?

Please see below for our jnlp file:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="http://192.168.1.169/webstart/" href="launch.jnlp" spec="1.0+">
    <information>
        <title>PrinterWebStart</title>
        <vendor>robert</vendor>
        <homepage href=""/>
        <description>PrinterWebStart</description>
        <description kind="short">PrinterWebStart</description>
    </information>
    <update check="always"/>
    <security>
<all-permissions/>
</security>
    <resources>
        <j2se version="1.5+"/>
        <jar href="printer-base.jar" main="true"/>
    </resources>
    <application-desc main-class="com.ccti.printer.task.PrinterTaskPanel">
    </application-desc>
</jnlp>

Solution

  • The proper way to package a web-start app is to list the library jar files you are using in a <resources> tag as you are doing. My project uses 12 library files and the launch time is still quite good. When the program launches the second time, all the client PC needs to do is check that the jar files have not changed. This makes future launches extremely quick.

    If you have many different jar files in your library, you might be concerned that comparing the last-modified dates of these files on the server to the versions stored locally could waste some time. To make this update check more efficient, you can sepecify the version number in your resource files and thus avoid unnecessary update checks.

    If the JNLP needs to contain signed code, then it might feel like a pain to have to sing all of those jar files one at a time. To simplify this process, consider the following ant script that signs all of the jars in the lib folder.

    <target name="signLibs">
       <signjar destDir="signed"  alias="aliasName" keystore="yourKeyStoreName"
          storepass="PaSSW0rD" force="true" >
       <path>
          <fileset dir="lib" includes="*.jar" />
       </path>
       </signjar>   
       <echo message="Library files were signed."/>
    </target>