Java Software Licensing

Hello World

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
     [copy] Copying 1 file to C:\nuvovis_2.0.1490\java\dist
     [copy] Copying 1 file to C:\nuvovis_2.0.1490\java\dist
     [copy] 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.