Skip to main content

Distribute your Swing application via Java Web Start!

You have developed a nice desktop application and have been breaking your head to create an executable to distribute for different platforms! Here comes Java Web Start for your rescue, distribute your Swing application via web, no installers, no custom code for desktop shortcuts, no tweaks for auto-upgrades! Let me explain the process step by step.

Step 1: Jar your classes and resources using your favorite build tool.
Say your jar file is myswingapp.jar, rename it to myswingapp__V1.0.jar, ie, add '__V' and an initial version say 1.0. I will explain why this is needed in the coming section.
Step 2: Organize your dependencies as below:
root _folder>myswingapp__V1.0.jar
root _folder>jarfile1.jar
root _folder>jarfile2.jar
root _folder>jarfile3.jar
Step 3: Create a jnlp file as below and save it as myswingapp.jnlp

<?xml version="1.0" encoding="UTF-8"?>
<jnlp codebase="http://mysite.com/downloads/" 
        href="myswingapp.jnlp">
    <information>
        <title>MySwingApp</title>
        <vendor>MyOrg</vendor>
        <description>A swing application</description>
        <icon href='logo48.png' kind='default'/>
        <icon kind="shortcut" href="icon.jpg" width="32" height="32"/>
        <offline-allowed/> 
        <shortcut online="false">
       <desktop/>
       <menu submenu="MySwingApp"/>
     </shortcut>
    </information>
    <security>
       <all-permissions/>
 </security>
 <update check="background"/>
    <resources>
     <j2se version="1.6.0+"/>
        <jar href="myswingapp.jar" main="true" version="1.0"/>
        <jar href="jarfile1.jar"/>
        <jar href="jarfile2.jar "/>
        <jar href="jarfile3.jar "/>
        <property name="jnlp.versionEnabled" value="true"/>
    </resources>
    <application-desc main-class="com.myorg.Main"/>
</jnlp>

Step 4: Copy all your jar files and the jnlp file to  mysite.com/downloads/
Step 5: Create your download page say download.html and add the below script:

<script src="http://www.java.com/js/deployJava.js"></script>
<script type="text/javascript"> 
    var url = "http://mysite.com/downloads/myswingapp.jnlp";
    deployJava.createWebStartLaunchButton(url, '1.6.0');
</script>

Step 6: You are done! Now you can launch your application by accessing your download page, just click on the 'Launch' button, the installer will download your application and install it with a desktop shortcut as well as a menu item to launch the application. Great, isn't it?

Signing jars: If you want your application to run with full access, you must sign all your jar files.
Updates: An update check will be performed in the background and if an update is available, the application will download it and install it in the background! You just need to put your latest jar files, that's it!

Feel free to drop your comments. I will address your queries based on time availability!

Create Your Own Programming Language

A system to achieve every programmer’s dream. Learn how to create a simple programming language in a few days with this easy step-by-step guide.

Comments

  1. hi,
    I have the file myswingapp__V1.0 and myswingapp.jnlp as you gave as an example in my directory. But when I click it gives the error;
    unable to load resource: (file://localhost/C:/documents and settings/user/desktop/myswingapp.jar?version-id=1.0, 1.0)
    at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
    ..
    ..
    ..

    Also it gives a Wrapped Exception Error:
    java.io.FileNotFoundException: file://localhost/C:/documents and settings/user/desktop/myswingapp.jar (System could not find the file)
    at java.io.FileInputStream.open(Native Method)
    ...
    ..
    ..

    When I erase these parts from jnlp file and make my jar file as myswingapp.jar it works;
    update check="background"/

    property name="jnlp.versionEnabled" value="true"/

    and

    version="1.0" part at jar href="myswingapp.jar" main="true" ...

    Can you help me with this problem?

    ReplyDelete
  2. Hi Barbaros,

    You should follow the naming convention jarfile__V1.0.jar

    Cheers,
    Sunil.

    ReplyDelete
  3. I mentioned wrong in the first post but I have already named my file as myswingapp__V1.0.jar and have those problems.

    ReplyDelete
  4. Deploy your jnlp file in a web server, change your base url in jnlp accordingly.

    Also recommend you to upgrade to the latest version of Java as Java Web Start is not stable in any of the previous releases.

    Let me know whether it works or not.

    ReplyDelete
  5. how the jnlp file will executed

    ReplyDelete
    Replies
    1. Command line: javaw
      Some browsers automatically opens jnlp file on clicking jnlp file link.

      Delete

Post a Comment

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to our feed and get articles like this delivered automatically to your feed reader? Like our Facebook Page.

Popular posts from this blog

HDFC Bank introduces Missed Call Service to know Account Balance

Missed call is a powerful business tool in developing countries like India where customers give a miss call to specific phone numbers for getting account details, providing feedback, voting etc. On receiving a missed call from a registered phone number, the underlying app performs a phone number lookup and sends the data to the caller via text message(SMS) or records the call details for future processing.HDFC Bank recently introduced missed call service for its retail customers which allows to retrieve bank account details, mini statement etc. by simply giving a miss call to their toll free numbers.Following services are now available: 1800 270 3333 - Account Balance 1800 270 3355 - Mini Statement 1800 270 3366 - Request for new Cheque Book 1800 270 3377 - Request for Bank account statement Also you can download HDFC Mobile Banking Application by giving a missed call to : 1800 270 3344. Other banks providing missed call serviceAxis bank(known as Axis Dial) - 09225892258Bank of India…

Induction Cooker Showing an Error Code? Induction Cooker Error Codes Explained

Are you searching for Induction Cook-top error codes? Here you can find the error codes of all popular induction cooktops and how to troubleshoot it.

These are for your reference only, do not try to open your cooktop without proper safety measures, we advise you to call the service person if any servicing is needed.

If you want to know how Induction Cook-top works, read our previous article titled What is Induction Cooker? How Induction Cooker Works?.

Whirlpool Induction Cooker Error CodesError CodeErrorSolutionF0An internal error was detected.Disconnect power. Wait 5 seconds before reconnecting power. If the symbol appears again, call for service.F2The surface cooking area is too hot and has turned off.Remove the pans from the surface cooking area. "F2" will disappear when the surface cooking area has cooled. If you turn the surface cooking area back on and "F2" reappears, the cooktop is still too hot. Turn off the surface cooking area and allow it to cool.F4The po…

LICHFL - Generating Home Loan Statements Online

Generating an online statement from LIC Housing Finance Ltd is very easy, simply follow the below steps to create an online account with LICHFL and generate statements online! You may use the online generated statement as a proof for principal paid for a housing loan(under section 80C) and interest paid(under section 24) while filing income tax returns.* Want to know how to save maximum income tax? Read our most read article how to save maximum income tax (opens in new tab).* Paying high interest to LICHFL? Learn how to reduce interest on your existing home loan (opens in new tab).
Before reading further, make sure you have the following information with you: Your Loan Account NumberSanctioned AmountStep 1 - Open LICHFL websiteVisit LICHFL website and click on the 'New Customers? Click Here' link(refer the below screenshot). Step 2 - Enter your loan account detailsFill in the following details: New Loan NumberSanctioned AmountDate of BirthSecurity Codeand click on the Submit b…