How to obtain temporary license and set licenses in GroupDocs.Viewer Java

Managing licenses efficiently is crucial when integrating third‑party libraries like GroupDocs.Viewer for Java into your applications. This guide shows you how to obtain a temporary license, set it from a local file or an HTTP URL, and verify that the license path is correct. By the end of this tutorial you’ll have a reliable, production‑ready licensing setup that keeps your app compliant and performant.

File and URL Setup with GroupDocs.Viewer for Java

Quick Answers

  • How do I obtain a temporary license? Request one from the GroupDocs temporary‑license page and download the .lic file.
  • Can I load the license from a URL? Yes – just point License.setLicense to an HTTP address that returns a valid license file.
  • What happens if the license path is missing? Implement a check to display guidance and prevent the viewer from starting.
  • Do I need to restart the app after changing the license? No, License.setLicense can be called at runtime.
  • Which Java version is required? JDK 8 or higher is recommended.

What is a temporary license?

A temporary license is a time‑limited key issued by GroupDocs that lets you evaluate the product without purchasing a full license. It behaves exactly like a permanent license while it’s valid, allowing you to test all features in a real‑world environment.

Why obtain a temporary license?

  • Fast evaluation: Get full functionality instantly for proof‑of‑concept projects.
  • No financial commitment: Test before you buy.
  • Easy integration: Works with the same API calls as a permanent license.

Prerequisites

  1. Java Development Kit (JDK): Version 8 or higher.
  2. IDE: IntelliJ IDEA, Eclipse, or any Java‑compatible IDE.
  3. GroupDocs.Viewer for Java library: Added to your project (see Maven setup below).
  4. Basic Java knowledge: Familiarity with classes, imports, and exception handling.

Setting Up GroupDocs.Viewer for Java

To get started, include the library in your Maven project.

Maven Configuration

Add the following configuration to your pom.xml file:

<repositories>
   <repository>
      <id>repository.groupdocs.com</id>
      <name>GroupDocs Repository</name>
      <url>https://releases.groupdocs.com/viewer/java/</url>
   </repository>
</repositories>
<dependencies>
   <dependency>
      <groupId>com.groupdocs</groupId>
      <artifactId>groupdocs-viewer</artifactId>
      <version>25.2</version>
   </dependency>
</dependencies>

Acquiring a License

To use GroupDocs.Viewer, obtain a license:

Basic Initialization

Once the library is added, you can initialize the viewer:

import com.groupdocs.viewer.License;

public class InitializeViewer {
    public static void main(String[] args) {
        License license = new License();
        // Set the path to your license file or URL here
        license.setLicense("YOUR_LICENSE_PATH");
        System.out.println("GroupDocs.Viewer initialized successfully.");
    }
}

How to obtain temporary license and set it from a file

Overview

Setting a license from a local file is the most straightforward approach and works even when the application runs offline.

Implementation Steps

  1. Define the License Path – point to the .lic file you received after requesting a temporary license:
final String licensePath = "YOUR_DOCUMENT_DIRECTORY/your-license-file.lic";
  1. Apply the License – use the License class to load it:
import com.groupdocs.viewer.License;

public class SetLicenseFromFile {
    public static void run() {
        if (licensePath != null && !licensePath.startsWith("http")) {
            License license = new License();
            license.setLicense(licensePath);
            System.out.println("License set successfully.");
        } else {
            // Handle cases where the path is not valid
            System.err.println(
                "We do not ship any license with this example.\n" +
                "Visit the GroupDocs site to obtain either a temporary or permanent license.\n" +
                "Learn more about licensing at https://purchase.groupdocs.com/faqs/licensing.\n" +
                "Lear how to request temporary license at https://purchase.groupdocs.com/temporary-license.");
        }
    }
}

Tips:

  • Verify that the file path is absolute or relative to the working directory.
  • Ensure the file has read permissions for the user running the JVM.

How to handle a license URL

Overview

A URL‑based license is handy for cloud deployments where the license file lives in a secure storage bucket.

Implementation Steps

  1. Define the License URL – replace the placeholder with your actual endpoint:
final String licensePath = "http://example.com/license.lic";
  1. Detect and Log URL usage – the sample below simply notifies you that a URL was supplied:
public class HandleLicenseURL {
    public static void run() {
        if (licensePath != null && licensePath.startsWith("http")) {
            System.err.println("License path was not provided, license URL is found instead!");
        }
    }
}

Tips:

  • In production you would download the file (e.g., with java.net.HttpURLConnection) and then call license.setLicense(stream).
  • Add retry logic and timeout handling to cope with transient network issues.

How to check license availability (verify license path)

Overview

Before attempting to load a license, it’s good practice to check license availability so you can guide developers or users to obtain a temporary license when needed.

Implementation Steps

  1. Simulate a missing license path:
final String licensePath = null;
  1. Provide clear guidance if the path is absent:
public class CheckLicensePathAvailability {
    public static void run() {
        if (licensePath == null) {
            System.out.println(
                "\nWe do not ship any license with this example.\n" +
                "Visit the GroupDocs site to obtain either a temporary or permanent license.\n" +
                "Learn more about licensing at https://purchase.groupdocs.com/faqs/licensing.\n" +
                "Lear how to request temporary license at https://purchase.groupdocs.com/temporary-license.");
        }
    }
}

Tips:

  • Log this message at startup so ops teams know a license is missing.
  • Consider exiting the application or disabling viewer features until a valid license is supplied.

Practical Applications

Understanding how to obtain a temporary license, set it from a file or URL, and verify license path availability unlocks several real‑world scenarios:

  1. Document Management Systems – embed a viewer that automatically validates its license on each launch.
  2. Cloud SaaS Platforms – store the license in a protected blob storage and load it via URL for zero‑downtime updates.
  3. Enterprise Deployments – use a temporary license during pilot phases before purchasing a full‑scale license.

Performance Considerations

  • Resource usage: Load the license once at application start‑up; repeated calls add unnecessary I/O.
  • Memory management: The License object holds minimal state, but always close streams if you download the license manually.

Conclusion

By following the steps above you can obtain a temporary license, configure GroupDocs.Viewer for Java using either a local file or an HTTP URL, and check license availability to keep your application compliant. This solid licensing foundation prevents runtime errors and gives you the flexibility to move between development, testing, and production environments with confidence.

FAQ’s

  1. How do I set a local license file in GroupDocs.Viewer Java?

    Use license.setLicense("path/to/license.lic") with the correct file path to apply a local license.

  2. Can I load a license directly from a URL?

    Yes, but ensure your code handles URL access, potentially downloading the license at runtime or managing network issues.

  3. What should I do if the license path is invalid or missing?

    Implement checks for null or invalid paths and provide guidance or fallback prompts to obtain a valid license.

  4. Is it possible to switch between license file and URL dynamically?

    Absolutely, by adding conditional logic to handle both scenarios based on your environment or runtime parameters.

  5. What are best practices for license management in production?

    Store licenses securely, verify their validity regularly, and implement error handling for license issues to ensure uninterrupted service.

Frequently Asked Questions

Q: How long does a temporary license last?
A: Typically 30 days, after which you can request a renewal or upgrade to a permanent license.

Q: Do I need an internet connection to use a file‑based license?
A: No. A local .lic file works completely offline once it’s loaded.

Q: Can I encrypt the license file for extra security?
A: The license file is already signed by GroupDocs; additional encryption is optional but not required.

Q: What happens if the license expires while the app is running?
A: Viewer operations will start throwing licensing exceptions; it’s recommended to check expiration on startup.

Q: Is it safe to store the license URL in source control?
A: Avoid committing sensitive URLs; use environment variables or secure configuration stores instead.


Last Updated: 2026-03-08
Tested With: GroupDocs.Viewer 25.2 for Java
Author: GroupDocs