How to...

Glue42 Enable Your App

Java

Installation

The Glue42 Java 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.

Glue42 Java 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.3.6.RELEASE</version>
        </dependency>
    </dependencies>
</project>

Gradle

apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile 'com.tick42.glue:tick42-glue-shaded:1.3.6.RELEASE'
}

Referencing and Initialization

To use Glue42 Java in your applications, you need add the Glue42 Java library and its dependencies to your application classpath, import the Glue class and create a Glue instance:

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 in your application, 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 application, 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 application classpath. If you are using Maven or Gradle as a build tool, you can place the glue.conf file for your application in the \src\main\resources folder of your project directory.

If you do not specify an application name in a glue.conf file, as in the example above, the name of the application will be taken from the Glue42 Enterprise starting context which contains configurations from the application definition file (see below).

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

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

Application Definition

To add your Java application to the Glue42 Enterprise 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\<ENV-REG>\apps folder to publish your own application locally. <ENV-REG> in the link should be replaced with the region and environment folder name used for the deployment of your Glue42 Enterprise - e.g., T42-DEMO. This way, your files will not be erased or overwritten, in case you decide to upgrade or change your Glue42 Enterprise 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).

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 detailed information about the application definitions, see the Configuration documentation.

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