License program in java

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

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:

  • Hyde.java — the Java class that includes my application’s main() method
  • LicenseableClass.java — an interface that Hyde.java implements to work with my True License controller
  • LicenseController.java — the «controller» class that uses the True License library
  • DDLoggerInterface.java — an interface that is referenced in the code
  • DDSimpleLogger.java — a class that implements the DDLoggerInterface

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.

Читайте также:  Access div in javascript

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.)

Источник

Java Software Licensing

To add license checking to a Java application you import the com.nuvovis.licensing. License class which wraps the Licensing Library and put the library in your execution path. You can then call the checkLicense method to load the license information and check that the user has a valid license. You need to specify a folder location for the license file, your developer password string, the license key issued to the user and the name of the application.

import com.nuvovis.licensing.License; int status = License.checkLicense(".", PWD, key, "Hello World"); if (status != License.LICENSE_OK)  throw new RuntimeException("Application not licensed"); > 

Building the Example

The library download includes a Java example application showing the use of the software licensing library with the developer password for the free test drive environment. For this step by step guide to building and running the example we will be using a Windows development machine, and the test drive web portal to create licenses for our test application. To build the example, in addition to a JDK you need Apache Ant or Eclipse set up on your machine. To use Eclipse create a new project and copy the java/src/com folder to your src folder. You also need to copy the pgslicmt.dll to PGSLIC.dll and add the folder containing the DLL to the project’s Native library location as shown in the screenshot of Eclipse below.

To build with ant change directory to the java folder and run the ant command. This will create a jar file in a sub-folder called dist. We will run the example from the dist folder. We need the pgslicmt.dll copied to PGSLIC.dll in our execution path so copy the DLL from the bin folder (32 bit) or bin64 to the dist folder.

C:\>cd nuvovis_2.0.1490\java C:\nuvovis_2.0.1490\java>ant Buildfile: C:\nuvovis_2.0.1490\java\build.xml compile: [javac] Compiling 2 source files to C:\nuvovis_2.0.1490\java\build dist: [mkdir] Created dir: C:\nuvovis_2.0.1490\java\dist [jar] Building jar: C:\nuvovis_2.0.1490\java\dist\nuvovis.jar  Copying 1 file to C:\nuvovis_2.0.1490\java\dist  Copying 1 file to C:\nuvovis_2.0.1490\java\dist  Copying 1 file to C:\nuvovis_2.0.1490\java\dist BUILD SUCCESSFUL Total time: 4 seconds C:\nuvovis_2.0.1490\java>cd dist C:\nuvovis_2.0.1490\java\dist>copy ..\..\bin64\pgslicmt.dll PGSLIC.dll 1 file(s) copied. 

Creating a License

Run the example using the rn batch file without any arguments. You should see the usage help text as shown below.

C:\Users\bob\Documents\nuvovis_2.0.1490\java\dist>rn Usage: java RomanNumeralsCmd Number Outputs the decimal number as Roman numerals java RomanNumeralsCmd -saveKey LicenseKey Activate the license java RomanNumeralsCmd -info View application version and license settings 

The example cannot run until we have created a license for the application. In the web portal click on the New button to create a new Software License. Change the client field to one of the customer names and the product name to «RomanNumerals». Save the new license to store the new license in Genux-B. The new Software License will now have a License Key field value. Copy and paste the license key into the command window as the argument to rn -saveKey:

C:\Users\bob\Documents\nuvovis_2.0.1490\java\dist>rn -saveKey 1-9-548-wKW6YF-nsrq5v-WWZcKf-rtaOKI License key saved 

Now our application is licensed and we can use it. Use rn -info to view the license settings.

C:\Users\bob\Documents\nuvovis_2.0.1490\java\dist>rn 99 Warning: Only 10 day(s) until license expires! XCIX C:\Users\bob\Documents\nuvovis_2.0.1490\java\dist>rn -info Warning: Only 10 day(s) until license expires! RomanNumerals Licensed to Massive Dynamic License expires on 2016-05-11 Maximum number = 1000 All settings = MaxLimit=1000 

Back in the web portal you can now see that the license has been used by clicking on the license id link in the license list view for the new Software License.

Nuvovis Limited, 86-90 Paul Street, 4th Floor, London EC2A 4NE, UK | support@nuvovis.com | Registered in England and Wales, Number 7560083

Источник

Java Software Product Licensing Solutions:

License4J provides solutions for Java software product licensing and protection. It includes Java API, License Manager GUI tool, Auto License Generation and Activation Server application and Floating License Server for generation and validation of license text, license key, and floating license file.

License4J is designed to be easy to use and integrate in any Java software application. A small pure Java runtime library provides static methods for license validation, online activation, deactivation and validation. Full featured License Manager provides wizard dialogs for generating licenses and license templates. It supports all types of software licensing methods with auto/manual license activation. Auto License Generation and Activation Server performs auto license generation, activation, deactivation, and online validation. Short video tutorials are available.

License4J Java Software Licensing

A single copy of License Manager provides all software licensing solutions. Online.License4J subscription is also included for online license generation, activation, deactivation and validation.

License4J includes a free Floating License Server application to host and serve generated floating licenses. It runs as a service on Windows, Linux and Mac OS operating systems. Floating licenses can be installed, updated, deleted and monitored locally or remotely with Floating License Server Administration GUI tool. Floating License Server and Administration GUI can be fully customized and internalized.

Auto License Generation and Activation Server version 1.7.3 is available on downloads page. It is a web application which handles auto license generation, activation, deactivation, blacklist check and license modification requests. It is deployed on a Tomcat and connects to the same database with License Manager to perform defined and allowed actions on licenses.

License Manager 4.7.3 and Floating License Server 4.7.2 is available on downloads page. License Manager has many GUI enhancements, and a new features.

License Activation and Validation Proxy Server version 1.7.2 is available on downloads page, it is appropriate for environments in which security concerns may restrict direct access to the Internet for license activation, deactivation and validation.

Источник

Оцените статью