What's new

+ Upgrading

These are the docs for 13.2, an old version of SpatialOS.The docs for this version are frozen: we do not correct, update or republish them.14.0 is the newest →

Setting up a Java worker

To add a Java worker to your project, create a directory under workers/ of your SpatialOS project
(for example workers/java), and create a worker configuration file
file, e.g. workers/java/spatialos.ExampleJavaWorker.worker.json, with the following contents:

The default build for the Java worker sets up a project that should get you started quickly,
lets you customize the build, and is upgradeable between SpatialOS versions. However, if you need to
customize it further, you can
turn off the automatic build script generation.

The worker project is controlled by you, and should provide you with enough flexibility without the need to turn off
automatically generated build scripts. The worker project depends on worker-sdk project, which includes the worker SDK
dependencies and the schema-generated code. The top-level build.gradle builds
self-contained assemblies required by SpatialOS in order to run your worker in the cloud.

You should now be able to build your worker using
spatial worker build or
spatial worker build <your_worker_type>. This will generate all the remaining project files, including the
worker-sdk subproject.

You will need to add the worker to your SpatialOS application.
Assemblies produced by spatial worker build contain a jar file with the same name as the rootProject.name
set in settings.gradle. For example, if the project’s settings.gradle contains
rootProject.name = "ExampleJavaWorker", it will produce an assembly containing
ExampleJavaWorker.jar. You should launch them using java -jar ExampleJavaWorker.jar,
or configure them to be launched by SpatialOS as
managed workers.