This tutorial shows how to get started with the LEADTOOLS SDK in a Java application.
Overview | |
---|---|
Summary | This tutorial covers how to set a license in a Java application. |
Completion Time | 30 minutes |
Project | Download tutorial project (1 KB) |
Platform | Java Application |
IDE | Eclipse |
Runtime License | Download LEADTOOLS |
Try it in another language |
|
Before any functionality from the SDK can be leveraged, a valid runtime license will have to be set.
For instructions on how to obtain a runtime license refer toObtaining a License.
Launch Eclipse and selectFile->New->Java Project, then add the project name and clickFinish.
In the new window it will ask to create a new module-info.java file, selectDon't Create. Once the project is created, right-click the project and selectNew->Package. Add a package name and clickFinish.
Add a new class to the package by right-clicking the package and selectingNew->Class. Add a name for the class and clickFinish.
To leverage the LEADTOOLS SDK in a Java project, references to the LEADTOOLS JAR files will be need.
Right-click on the Java project in thePackage Explorerand selectProperties. SelectJava Build Path, and click on theLibrariestab. SelectClasspath, then clickAdd External JARs....
Navigate to this path:
The following JAR file is required for this tutorial.
leadtools.jar
SelectOpen, then clickApply and Close
Open the_Main.java
class in thePackage Explorer. Add the followingimport
statements to the import block at the top.
importjava.io.IOException;
importjava.nio.file.*;
importleadtools.*;
Inside themain()
method add the following to set the library path to where the CDLL files are located, as well as load the LEADTOOLS library that was previously imported.
publicstaticvoidmain(String[] args)throwsIOException
{
Platform.setLibPath("C:\\LEADTOOLS21\\Bin\\CDLL\\x64");
Platform.loadLibrary(LTLibrary.LEADTOOLS);
}
With the project created and the references add, the set license code can be added.
In the_Main
class add a new method calledSetLicense()
and call the method at the bottom of themain()
method. Add the following code to properly set the LEADTOOLS license.
staticvoidSetLicense()throwsIOException
{
String licenseFile ="C:\\LEADTOOLS21\\Support\\Common\\License\\LEADTOOLS.LIC";
String developerKey = Files.readString(Paths.get("C:\\LEADTOOLS21\\Support\\Common\\License\\LEADTOOLS.LIC.KEY"));
RasterSupport.setLicense(licenseFile, developerKey);
if(RasterSupport.getKernelExpired())
System.out.println("License file invalid or expired.");
else
System.out.println("License file set successfully.");
}
Run the project by selectingRun->Run.
If the steps were followed correctly, a message in theConsolewindow will showLicense file set successfully
.
This tutorial showed how to create a new Java Project, add LEADTOOLS JAR and DLL references, and set the license.
This is the basis for all Java applications leveraging the LEADTOOLS SDK. All functionality in the SDK is unlocked via setting a license. TheSetLicense
method must be called before calling any other LEADTOOLS SDK methods.
Once the SDK is purchased, the evaluation license can be replaced with a valid runtime license to disable the Nag Message.