A True License example - Part 2, the Java Software License client

(This is my Java TrueLicense example, Part 2. A link to Part 1 of this example is available below.)

Earlier this spring (while stranded in a motel in Canada) I wrote a Java application named Hyde which can hide your desktop and desktop icons (as long as you're a Mac OS X user). I decided to try to sell Hyde as a commercial application, and as such, I needed a Java license manager. I thought about writing my own, but first I looked around and found several Java license manager tools/libraries, the best of which I thought was True License.

So I dug into the True License docs, and eventually created (1) a Java license server, which I put on a web server to dole out the software licenses when someone made a purchase, and (2) a Java license client, which I embedded in my Hyde application. Both of these were based on True License.

As this is a technical/education website, I eventually decided to share my True License client and server code. I first shared my True License Java license manager server code (Part 1 of this series), and in this article I'll share my True License client code.

My True License client code

One reason I've avoided publishing my True License client code is that this is a complicated subject, and hard to describe easily. I'll do what I can to introduce the code here today, and I'll also come back here and update this article when I have more time.

The first thing you need is the source code for the two Java classes and one interface I created to implement the True License license manager in my application. I recommend you open these files in new browser tabs or windows, or download them to your computer so you can look at them while reading the descriptions that follow. Here are links to these Java files:

The Hyde.java class

The class named Hyde includes the main() method for my application. Of course everything starts in main(), and main quickly hands things off to the Hyde() constructor. This constructor does some initialization work, displays the main frame of the application, and then calls the verifyLicense() method of the LicenseController class. If verification succeeds, nothing visible happens, and the user uses the application. If verification fails, the system displays a "Please License" dialog, which blocks the user from using the Hyde application until they purchase a license. The dialog I display to block the user from using the application included a link to a web page where they could buy a license.

The LicenseableClass interface

After getting True License to work with Hyde, I realized I could improve my design by:

  • Creating an interface
  • Making my LicenseController work with any class that implemented that interface
  • Making Hyde.java one class that implemented that interface.

By creating this interface, I thought I could easily re-use the LicenseController in other Java applications which I was thinking about selling.

After working with this True License client code for a while, I finally created an interface which I thought would make the LicenseController portable between different Java applications ... well, more or less portable ... I didn't completely finish the LicenseController part. I thought I'd finish that when I wrote my second application that I wanted to make licenseable, but I haven't gotten to that yet.

The LicenseController class

My LicenseController class handles almost all of the interaction with the True License library. I say "almost all of the interaction" because some things are handled as callbacks, and methods for those are handled in my Hyde class. Also, if you want the LicenseController class to be truly reusable, some of the True License ObfuscatedString instances need to be in the class which implements the LicenseableClass interface, which again is my Hyde.java class.

More Java license manager discussion ... coming soon

Well, sorry, but time is limited, and this is all the time I have for this today. I'll try to write more about my True License Java license manager software tomorrow, but if you're really in a hurry, I hope this helps you get started in the "Java license manager" world. (I've added some documentation to the classes, which will hopefully make them easier to understand.)