How to...

Glue42 Enable Your App

Java

Installation

The Java Glue42 library provides an easy way to make your enterprise Java applications Glue42 enabled. You can use the Glue42 Java library in the same way as any standard Java library.

Java Glue42 requires JDK 8+ (Java SE 8+) and is JDK 9+ ready.

Maven

<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>myproject</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.tick42.glue</groupId>
            <artifactId>tick42-glue-shaded</artifactId>
            <version>1.2.0.PREVIEW0</version>
        </dependency>
    </dependencies>
</project>

Gradle

apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile 'com.tick42.glue:tick42-glue-shaded:1.2.0.PREVIEW0'
}

Quick Start

import com.tick42.glue.Glue; 

try (Glue glue = Glue.builder().build()) 
{
    System.out.println(glue.version()); 
}

In the example above:

  • First, import the Glue42 package.

  • Glue is the main entry point of the SDK. It is thread-safe and you should create a single instance (per Glue42 application) and share it throughout your code.

  • Get the Glue42 version as a string.

Always close the Glue instance once you are done with it, in order to free up underlying resources (ws connections, thread pools, etc.). This example uses a try-with-resources block, because Glue extends AutoCloseable - in a real application, you will probably call close() or closeAsync() explicitly.

Configuration

To configure Glue42 Java, you can use .conf files, .properties files, .json files and system properties to externalize your configuration.

Here is an example of a minimal glue.conf file:

glue {
    application: "example"
}

Application Definition

To add your Java application to the Glue42 Desktop App Manager application, you need to define a configuration file and add it to the application config store. You can add the configuration file for your application in the %LocalAppData%\Tick42\UserData\<REG-ENV>\apps folder to publish your own application locally. <REG-ENV> in the link should be replaced with the region and environment folder name used for the deployment of your Glue42 Desktop - e.g., T42-DEMO. This way, your files will not be erased or overwritten, in case you decide to upgrade or change your Glue42 Desktop version.

Here is an example:

[
  {
    "title": "Java Example",
    "type": "exe", 
    "name": "java-example",
    "icon": "https://enterprise-demos.tick42.com/resources/icons/w2.jpg",
    "details": {
      "path": "", 
      "command": "java", 
      "parameters": "-Dglue.windows.sticky-agent=%GLUE-REGION%-%GLUE-ENV% -jar example.jar", 
      "mode": "tab"
    }
  }
]
  • type should be exe;
  • path is the path to the application - relative or absolute;
  • command is the actual command to execute (java);
  • parameters holds command line arguments;

Note that the definition should be a valid .json file (you should either use forward slash or escape the backslash).

For more detailed information about the application definitions, see the Configuration documentation.

You can also check out our Java examples at GitHub, demonstrating the various Glue42 Desktop features.