Package a Java component

A component extends a service with code the service can discover. For a new data format, implement a resource adapter. For computation on observations, implement a contextualizer in a library. For external identifiers, implement an authority. Use a plain Java client when your application only consumes those existing capabilities.

Generate a project

Use JDK 21 and the Maven settings that resolve the k.LAB build. Install the klab.component.archetype snapshot from its checkout with mvn install, or use the matching snapshot repository configured by your team. From the parent of the desired project, run this single command:

mvn org.apache.maven.plugins:maven-archetype-plugin:3.4.1:generate "-DarchetypeGroupId=org.integratedmodelling" "-DarchetypeArtifactId=klab.component.archetype" "-DarchetypeVersion=1.0.0-SNAPSHOT" "-DgroupId=org.example" "-DartifactId=field-tools" "-Dversion=1.0-SNAPSHOT" "-Dpackage=org.example.field" "-DincludeAgents=false" "-DincludeAdapter=false" "-DincludeIO=false" "-DincludeAuthority=false" "-DinteractiveMode=false"

This variation keeps the library template. The standard archetype can also generate actor, adapter, import/export and authority templates. Keep the generated KlabComponent plug-in entry point and the packaging configuration. Component archetype

Declare the executable contract

A library names a family of operations with @Library. A @KlabFunction describes an operation's inputs, output artifact, accepted geometry and parameters. These declarations affect where the platform can use the implementation. Specify the actual geometry and data layout that your code handles.

For a concrete example, inspect TerrainGenerators.generateTerrain in the generators component. The library is klab.generators.geospatial, the function is terrain, and the implementation requests a double scanner for a two-dimensional grid. Its in-memory calculation is intended for small areas. A test of this function should check both its numeric output bounds and how it treats the requested extent. Generators source

Package, install and check discovery

  1. Run mvn verify in the generated project. Open target/field-tools-component-1.0-SNAPSHOT.jar with jar tf. Look for META-INF/MANIFEST.MF, META-INF/extensions.idx and your library class. The packaging plug-in excludes dependencies provided by the host.
  2. Run mvn install to install the classified artifact in your local Maven repository. Maven records the packaged bytes with the classifier component and extension kar. For this example the repository filename is field-tools-1.0-SNAPSHOT-component.kar. With service administration rights, upload that file using component.kar.import, or use component.maven.import with org.example:field-tools:1.0-SNAPSHOT. Coordinate-based import requires a repository the hosting service can read.
  3. Inspect the host's component descriptor and advertised capabilities. For an adapter, confirm the operation your resource needs is available. For a function, exercise it with a small known resource or model and inspect the resulting activity and values.

Maven imports retain their coordinates for subsequent update checks. A directly uploaded archive is updated by supplying a replacement. Distinguish the canonical geospatial component from local development forks with the same coordinates when reproducing a deployment. Implement an authority