Set up a Java client project

Use the Java client when an application needs to ask for observations, navigate an existing twin or integrate k.LAB into a scientific workflow. The public domain and service contracts live in org.integratedmodelling:klab.core.api. The reference Engine, client scopes and service clients live in org.integratedmodelling:klab.core.common, which also brings in the API.

Match the client to the services

Use JDK 21 and Maven 3.9 for this edition. The example uses the services checkout's 1.0.0-SNAPSHOT artifacts. A SNAPSHOT coordinate can refer to successive builds. Choose the sources or deployment-matched artifacts for the Runtime you intend to call.

From the matching klab-services checkout, install the common client and its reactor dependencies. On Windows use .\mvnw.cmd for the wrapper.

./mvnw -pl klab.core.common -am install -DskipTests

The services build may also need the configured k.LAB snapshot repositories for its language and other external dependencies. Use the same Maven settings as your services checkout. If your organization already provides the matching snapshots, use that repository or local installation.

Compile the example

In a clone of this handbook the project is in docs/examples/observation-client/. If you are reading the rendered handbook, save the POM in a new directory and the Java source under src/main/java/org/example/klab/ beneath it. Maven POM ยท ObserveQuality.java

mvn compile exec:java "-Dexec.args=--help"

The help output identifies three operations. One argument lists visible twins on the named Runtime, two list a twin's root observations, and four submit a quality for a subject. Help runs without a Hub account. For the other operations, configure an authenticated user certificate and ensure the cooperating services are operational. Set up the user and services

Choose the right scope

Object What it supplies
Engine Authentication, discovered services and status changes. One host application should own its Engine lifecycle.
UserScope The identity under which the application sees services, sessions and accessible twins.
SessionScope A runtime-hosted session under which a new twin can be created.
ContextScope A particular digital twin. A derived scope can select a subject or an observer while retaining the twin.

Service discovery continues as services come online. The example listens for an operational Runtime with the requested service ID, checks already discovered instances and uses a bounded wait. This prevents a second visible Runtime from silently receiving the request. An application embedded in a running Modeler can reuse the host's scope. A standalone client initializes its own Engine and shuts it down on exit. Submit and inspect a quality