Java for Servers & Desktop
Integrate the Ditto SDK into Java Server & Desktop projects
Prerequisites
Following are the minimum requirements that must be met before attempting to install Ditto.
-
Java Development Kit (JDK) version 17
-
One of the following platforms and architectures:
- Windows x86_64
- MacOS arm64 (Apple Silicon)
Additional Resources
Setting Up Your Environment
Include the Maven Central repository in your Gradle file, and then synchronize it with your project.
From your project-level build.gradle file located in the project’s root directory,
ensure the mavenCentral()
repository is included in the repositories section:
Synchronize your project with the Gradle file by clicking Build > Sync Project with Gradle Files
Adding the Ditto SDK Dependency
To reduce the size of your final application archive, we provide binaries for each supported platform and architecture separately. You can include all supported binaries or only the ones you need.
Add the Ditto SDK to your module’s build.gradle
file in the dependencies
block with the appropriate version.
This is the Java API that you will use to interact with Ditto.
Add binaries to the same dependencies
block based on what platforms you are targeting.
Integrating and Initializing
Add the following code to import Ditto, at the top of your project file.
Most apps require that Ditto run as a singleton. A singleton is an implementation ensuring your Ditto instance accesses and shares a single object instance throughout your app.
To store the Ditto instance as a singleton object, create a custom Ditto subclass that can be used throughout the application.
By doing so, you ensure that there is only one instance of Ditto throughout the app’s lifecycle, and it remains available for use by any activity or component that needs it. This approach helps in efficient resource management and avoids unnecessary object instantiation and destruction.
Replace the variables with your access credentials available in the portal.
For instructions on how to obtain your access credentials, see Getting SDK Connection Details.
Was this page helpful?