Glue42 Enterprise is now io.Connect Desktop! The new documentation site for all interop.io products is located at docs.interop.io.

How to...

Installation

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

The Glue42 Java library is available as a package in the Maven Central Repository and as a part of the Glue42 Enterprise installer. It is highly recommended to use the shaded version of the library from the java-glue42-shaded artifact.

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

For Glue42 Java to work with Java SE 17+, you must pass the following parameters to the JVM:

--add-opens java.desktop/java.awt=ALL-UNNAMED
--add-opens java.desktop/sun.awt.windows=ALL-UNNAMED
--add-exports java.desktop/java.awt.peer=ALL-UNNAMED

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.glue42</groupId>
            <artifactId>java-glue42-shaded</artifactId>
            <version>1.4.14</version>
        </dependency>
    </dependencies>
</project>

Gradle

apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile 'com.glue42:java-glue42-shaded:1.4.14'
}

Referencing & Initialization

To use Glue42 Java in your apps, add the Glue42 Java library and its dependencies to your app classpath, import the Glue class and create a Glue instance.

The following example demonstrates how to initialize the Glue42 Java library and access information about the Glue42 version, environment and region:

import com.tick42.glue.Glue;

try (Glue glue = Glue.builder().build())
{
    // Print out the Glue42 version.
    System.out.println(glue.version());

    // Print out the Glue42 environment.
    System.out.println(glue.env());

    // Print out the Glue42 region.
    System.out.println(glue.region());
}

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

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 app, you will probably call close() or closeAsync() explicitly.

App Shutdown

Available since Glue42 Enterprise 3.10

When initializing Glue42, you can pass an event listener that will notify your app when it is about to be stopped. This is useful when your app/process isn't started directly by Glue42, but rather by Glue42 invoking a script/batch file or another app that in turn starts your app. With this listener you can properly shut down your app, free resources, etc.

Below is an example of passing a shutdown request listener when initializing Glue42:

Glue.builder()
        .withShutdownRequestListener(glue -> {
            System.out.println("Starting shutdown procedure...");
            glue.closeAsync();
        })
        .build();

App Configuration

To configure your Glue42 enabled Java app and add it to the Glue42 Toolbar, you can use CONF, PROPERTIES, JSON files and system properties to externalize your configuration. For example, if you want to specify a name for your app, you can do so in a glue.conf file:

glue {
    application: "My Java App"
}

Glue42 Java will look for a Glue42 configuration file in the app classpath. If you are using Maven or Gradle as a build tool, you can place the glue.conf file for your app in the \src\main\resources folder of your project directory.

If you don't specify an app name in a glue.conf file, as in the example above, the name of the app will be taken from the Glue42 Enterprise starting context which contains app configurations from JSON files.

You can also set the app name runtime when initializing the Glue42 Java library, which will override any previous configurations:

Glue.builder().withApplicationName("My Java App").build();

JSON app configuration files must be placed in the %LocalAppData%\Tick42\UserData\<ENV>-<REG>\apps folder, where <ENV>-<REG> must be replaced with the environment and region of your Glue42 Enterprise copy (e.g., T42-DEMO).

The following is an example JSON configuration for a Java app:

[
    {
        "title": "Java Example",
        "type": "exe",
        "name": "java-example",
        "icon": "https://enterprise-demos.tick42.com/resources/icons/w2.jpg",
        "details": {
            "path": "",
            "command": "java",
            "parameters": "-jar example.jar",
            "mode": "tab"
        }
    }
]

Note that if you want to pass parameters to the JVM - e.g., to ensure compatibility of Glue42 Java with Java SE 17+ (see Installation), you must pass them before the command for running the executable JAR file - e.g., before "-jar example.jar".

Property Description
"type" Must be "exe".
"path" The path to the app - relative or absolute.
"command" The actual command to execute (java).
"parameters" Specifies command line arguments.

To be able to start Glue42 Java on a dual core machine, you have to pass the -Dglue.gateway.ws.max-pool-size=3 parameter to the JVM by adding it to the "parameters" property described above.

For more details, see the Developers > Configuration > Application section.

Glue42 Java Concepts

Once you have created a Glue instance, your app has access to all Glue42 functionalities. For more detailed information on the different Glue42 concepts and APIs, see: