ObjectBox Data Sync Setup Steps for Java (5 Minute tutorial)

Note: ObjectBox Data Sync always includes MongoDB Connector

1Register for Trial

2Pull Docker Image

docker pull objectboxio/sync-server-trial

3Update Build Configuration

Go to your gradle build file and make this change:

// Change from: apply plugin: 'io.objectbox' // To: apply plugin: 'io.objectbox.sync'

4Add @Sync to Entities

Add the import and annotation to each entity you want to sync:

import io.objectbox.annotation.Sync; // Add this import @Sync // Add this annotation @Entity public class YourEntity { // Your entity fields (no relationships to non-synced entities) }

5Generate Data Model

  • Build project → find gradle-support/objectbox-models/default.json
  • Copy to project root as objectbox-model.json

6Start Sync Server

Windows:
docker run --rm -it --volume "%cd%:/data" --publish 127.0.0.1:9999:9999 --publish 127.0.0.1:9980:9980 objectboxio/sync-server-trial --model /data/objectbox-model.json --unsecured-no-authentication --admin-bind 0.0.0.0:9980
Linux/Mac:
docker run --rm -it --volume "$(pwd):/data" --publish 127.0.0.1:9999:9999 --publish 127.0.0.1:9980:9980 objectboxio/sync-server-trial --model /data/objectbox-model.json --unsecured-no-authentication --admin-bind 0.0.0.0:9980

7Add Sync Client to App

Add these imports to your main application class:

import io.objectbox.sync.Sync; import io.objectbox.sync.SyncClient; import io.objectbox.sync.SyncCredentials;

Add this code after creating your ObjectBox store:

if (Sync.isAvailable()) { SyncClient syncClient = Sync.client(store, "ws://127.0.0.1:9999", SyncCredentials.none()).build(); syncClient.start(); logger.info("Sync client started"); }
Note:
  • Important: Never close ObjectBox store while sync is active (generally, there is rarely ever need to close the store, so if you feel you need to, be very careful with this)
  • Only sync entities that don't have relationships to non-synced entities
  • Vector embeddings are not yet syncable (reach out to us if you need this!)
  • Keep the store open throughout application lifecycle
  • To test, run app with different database paths and add data in one instance, verify it syncs to the other