Posts from October 2010
Java Web Start (jnlp) simple example

UPDATE (2013/05/28): Since most people already know, WebStart is a bit of a crappy piece of tech with a bunch of limitations. The good news is there are alternatives :)

One of my current projects requires me to deliver a Swing application via Java Web Start. This meant some research to figure out how that works. Since i’m a nice guy, here’s the result for everyone that needs it.

As you can see - in the folder structure image - there are some files that are required for the whole thing to work. Here’s a brief explanation about each of them (in my creation order ;)):

  • src/org/Test.java : My source code. It's just a simple main that creates a JFrame and displays it;
  • Manifest.txt : The manifest file used to create the jar file that gets served by Java Web Start;
  • faren.jar : My application's jar. I'll explain how to create it in a while;
  • faren.jnlp : The Java Web Start description file;
  • faren.html : The html file that contains the button to start the application.

The first thing we want to do is create the source file. In the case of my simple test, here are its contents (blank lines removed for brevity):

Test.java

package org;

import javax.swing.JFrame;
import java.awt.Dimension;

public class Test {
  public Test() {
    JFrame faren = new JFrame("Test");
    faren.setSize(new Dimension(300, 300));
    faren.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    faren.setVisible(true);
  }
  public static void main(String[] args) {
    new Test();
  }
}

Moving on to the jar manifest file, it basically just says what the main class will be:

Manifest.txt

Main-Class: org.Test

Creating the jar is as simple as running the following command:

jar cfm faren.jar Manifest.txt org

It creates the faren.jar file, using the manifest file and the sources contained within the org folder. If - like me - you use Maven, you will have this for free using the app-assembler plugin, but for the test’s purposes i didn’t want to create a full maven project :)

Now we need to define a description file for the Java Web Start mechanism:

faren.jnlp

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="file:///Users/pedroassuncao/Desktop/jnlp_example">
  <information>
    <title>Dynamic Tree Demo</title>
    <vendor>Dynamic Team</vendor>
  </information>
  <resources>
    <!-- Application Resources -->
    <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="faren.jar" main="true" />
  </resources>
  <application-desc
    name="Dynamic Tree Demo Application"
    main-class="org.Test"
    width="300"
    height="300">
  </application-desc>
  <update check="background"/>
</jnlp>

Just to explain a little bit of what is going on in here (the important parts), what you want to make sure is that the codebase property is set correctly to the absolute path where the html file will be served from (in the case of a final deployment this will be something like http://myserver/jnlp/myapp, but in this case i’m serving without a web server, hence the file:/// part). You will also want to define a minimum version for the virtual machine of the client (the 1.6+ part) and eventually extend this information with the <shortcut> tag, that allows you to ask web start to create a desktop icon for your application on the clients’ computers. A full description of the structure of this file can be found here.

Finally, we need an html file that will show the java web start button. The following will suffice for now:

faren.html

<html>
  <head></head>
  <body>
    <script src="http://www.java.com/js/deployJava.js"></script>
    <script>
      // using JavaScript to get location of JNLP file relative to HTML page
      var dir = location.href.substring(0, location.href.lastIndexOf('/')+1);
      var url = dir + "faren.jnlp";
      deployJava.createWebStartLaunchButton(url, '1.6.0');
    </script>
    <noscript>
      <a href="faren.jnlp">Launch</a>
    </noscript>
  </body>
</html>

If the client’s browser supports javascript, this will use a special script from the java website that will ask to install the virtual machine if the client does not have it (or upgrade an existing one). If he doesn’t support javascript it will just show a link that will try to launch the java web start (depending a lot on whether the user’s file associations are correct (i.e. .jnlp files being assigned to the java executable).

Finally, with all this in place, point your browser to the place where you have the faren.html file and click the button; the application should launch.

By the way, does anyone know why my desktop shortcut is not being added on OSX? :)


Got something to say?

I would bet on this horse


Got something to say?

Summing up Apple's keynote

Apple had an event yesterday. And i saw that it was goooood. Seriously now, i was pleasantly surprised by - well - the surprises that were shown by Steve and co. Here’s a brief sum of coolness:

iLife 11

This update to the iLife family of products is one of the best ever, in my opinion.

iPhoto got yet more social features into it, like the ability to display your Facebook photo albums, as well as comments from your friends on those photos, and the fact that you can zoom to a particular part of the world map and, with one click, see the pictures inside that area. Other interesting features include a full screen mode, that takes away everything that is peripherical when organizing your pictures. They also introduced new slideshow templates and the books feature is very, very enhanced, showing a bookcase with all the photo book projects you have created and giving you complete control on the generation of the book.

iMovie also was added a lot of nice new features. The most notable include the long waited ability to edit audio directly in the timeline, like adjusting the sound level (even for just parts of a clip) and do fade ins and fade outs. Another great feature is the trailers part. It can now help you take your favorite footage and create movie-trailer-like movies, effortlessly. I can see myself using almost all these features in my podcast :D

GarageBand got some love as well: Between the ability to match the groove, or beat, of a track to another one, hence turning out-of-sync tracks into fully synced ones (which looks like magic), and a feature that reminds me of Guitar Hero called “How did i play”, GarageBand gets an incredible boost in terms of helpful features for artists and aspiring musicians.

No word on the rest of the products, but i can imagine some updates as well, though probably minor.

FaceTime for Mac

Yep, it’s here and fully available. You can now make video calls between iPhones and Macs (or macs and macs as well). Pretty awesome, though i wonder what will happen to iChat, and why wasn’t that integrated…

Mac AppStore

Will be available in 90 days time (yes, also for Snow Leopard) and will rock. These guys are going to make a ton of money on this thing. And for the end user, well, it means no longer manually installing updates for your favorite apps or using the (somehow) disparate software update mechanism in OSX.

MacBook Air

In one word: “Freakinawesome” :) No more spinning drives (yes, that means no optical drive as well: goodbye DVDs), which pretty much makes them lighter and smaller. 2 versions are available, one 13 inch and one 11 inch. The prices go from $999 to $1599, depending on the version and options you want.

OSX 10.7 Lion

They showed off some new features, though the most notable ones are:

  • A new dashboard: Where you can see all your installed apps from the Mac AppStore, like you do one your iPhone (yes, sliding panels and everything), and group them as well;
  • Full screen apps. Meaning, real fullscreen goodness for your applications. They basically want to make Lion a bridge between traditional OSX and the iOS, where every app is basically fullscreen;
  • Something called mission control, where you can see an overview of every app that is running on your Mac, be it fullscreen or windowed. Think Exposé, but better arranged.

What about you? What are your thoughts on Apple’s new features?


Got something to say?

Love this Dilbert strip

Cross-train to be an Engineer


Got something to say?

Video- 100th skydive

My 100th jump and Ricardo’s 2nd cutaway from Pedro Assunção on Vimeo.


Got something to say?

How does one change his domain name without losing hits?

I recently decided to drop one of the domain names that points to my blog. After (finally) getting the proper domain (pedroassuncao.com), i figured there was no sense anymore in keeping the old one (diffract.me).

Now here’s the problem: A lot of google links that bring a huge percentage of my traffic are pointing to the old one. That explains why - from last week to this one - i got a 90% traffic decrease in visits and page views. I definitely should have done something to prevent or at least minimize this “problem”, but i didn’t.

So my question is: What could i have done? Anyone out there has had this problem before? If so, what did you do to mitigate it?

UPDATE: Thanks for all the comments, that was really helpful. One in particular (by Ryan) explains a nice solution really in detail.


Got something to say?