---
title: Get started with the JRE Java SDK
description: "Install the Amplitude JRE Java SDK, initialize it, send a first event from a JVM application, and fix the problems that stop server-side events from arriving."
product: analytics
lang: en
last_updated: 2026-12-01
token_estimate: 2338
---
# Get started with the JRE Java SDK

- **Package:** `com.amplitude:java-sdk` ([maven](https://search.maven.org/artifact/com.amplitude/java-sdk))
- **Latest version:** 1.13.1

This guide helps you install the JRE Java SDK (`com.amplitude:java-sdk`), initialize it, and send one event from a JVM application to Amplitude. Each step lists the conditions that commonly break that step, so you can fix a problem where it happens. For every setter, go to [Configuration options](https://amplitude.com/docs/sdks/analytics/java/jre-java-sdk/reference#configuration-options). For changes between versions, go to the [Java SDK changelog](https://github.com/amplitude/Amplitude-Java/blob/main/CHANGELOG.md).

> For AI agents: a documentation index is available at [/docs/llms.txt](/docs/llms.txt). Append `.md` to any page URL for markdown, or send `Accept: text/markdown`.

The JRE Java SDK is for server-side and desktop JVM code, including Kotlin and Scala. The SDK doesn't store a user ID, device ID, or session between calls, and it collects no device data. Set identity and context on each event. For Android apps, use the [Android-Kotlin SDK](https://amplitude.com/docs/sdks/analytics/android/android-kotlin-sdk/get-started) instead.

## Prerequisites

- An Amplitude project and its API key. Find the key in _Settings > Projects > your project > General_.
- The data center your organization uses: US (default) or EU.
- Java 8 or later. The SDK compiles to Java 8 bytecode. The examples on these pages run on Java 17.
- The latest SDK release, or a pinned version you check against the [changelog](https://github.com/amplitude/Amplitude-Java/blob/main/CHANGELOG.md) for the features you use.

## Install the SDK

Add the SDK and `org.json`. The SDK declares `org.json` as a runtime dependency only. Your code can't use `JSONObject`, the type of event and user properties, unless you add `org.json` yourself. Use version `20231013` or later, the version the SDK compiles against.

#### Gradle

```groovy
dependencies {
    implementation 'com.amplitude:java-sdk:1.13.1'
    implementation 'org.json:json:20231013'
}
```

#### Gradle (Kotlin)

```kotlin
dependencies {
    implementation("com.amplitude:java-sdk:1.13.1")
    implementation("org.json:json:20231013")
}
```

#### Maven

```xml
<dependency>
  <groupId>com.amplitude</groupId>
  <artifactId>java-sdk</artifactId>
  <version>1.13.1</version>
</dependency>
<dependency>
  <groupId>org.json</groupId>
  <artifactId>json</artifactId>
  <version>20231013</version>
</dependency>
```

#### JAR files

Download both JAR files from Maven Central and add them to your classpath:

- [`java-sdk-1.13.1.jar`](https://repo1.maven.org/maven2/com/amplitude/java-sdk/1.13.1/)
- [`json-20231013.jar`](https://repo1.maven.org/maven2/org/json/json/20231013/)

### Fix installation problems

| Symptom | Cause | Fix |
| --- | --- | --- |
| `package org.json does not exist`, or `cannot find symbol: class JSONObject` | Your build has only the SDK. `org.json` reaches the runtime classpath, not the compile classpath. | Add `org.json:json:20231013` as a dependency. |
| `java.lang.NoClassDefFoundError: org/json/JSONObject` at runtime | You added the SDK JAR by hand without `json-20231013.jar`. | Add the `org.json` JAR to the classpath. |
| `java.lang.UnsupportedClassVersionError` | The JVM is older than Java 8. | Run on Java 8 or later. |

## Initialize the SDK

Get an instance, then call `init()` with your API key once, when your application starts.

```java
import com.amplitude.Amplitude;

Amplitude client = Amplitude.getInstance();
client.init("AMPLITUDE_API_KEY");
```

`getInstance()` returns the same object every time you call it, so other classes can call `Amplitude.getInstance()` instead of passing the client around.

If your project uses the EU data center, set the EU endpoint with `setServerUrl()` after `init()`:

```java
Amplitude client = Amplitude.getInstance();
client.init("AMPLITUDE_API_KEY");
client.setServerUrl("https://api.eu.amplitude.com/2/httpapi");

client.logEvent(new Event("Sign Up Completed", "user-12345"));
```

### Fix initialization problems

| Symptom | Cause | Fix |
| --- | --- | --- |
| `Flush Thread Error: ... ClassCastException: class sun.net.www.protocol.http.HttpURLConnection cannot be cast to class javax.net.ssl.HttpsURLConnection` | `setServerUrl()` received an `http://` URL. The SDK sends only over HTTPS. | Use an `https://` URL. |
| Events go to the default US endpoint, though you called `setServerUrl()` | The URL doesn't start with `http://` or `https://`, so the SDK ignored it. | Pass a full URL, such as `https://api.eu.amplitude.com/2/httpapi`. |
| Events go to HTTP V2, though you called `useBatchMode(true)` | You called `useBatchMode()` before `init()`. `init()` turns batch mode off. | Call `useBatchMode(true)` after `init()`. |

## Send a first event

Log one event for a user, then flush and shut down before the program ends. Pass the user's ID to the `Event` constructor, because the SDK doesn't remember identity between calls.

```java
import com.amplitude.Amplitude;
import com.amplitude.Event;

public class FirstEvent {
  public static void main(String[] args) throws InterruptedException {
    Amplitude client = Amplitude.getInstance();
    client.init("AMPLITUDE_API_KEY");

    Event event = new Event("Sign Up Completed", "user-12345");
    event.addEventProperty("plan", "starter");
    client.logEvent(event);

    client.flushEvents();
    client.shutdown();
  }
}
```

`logEvent()` only adds the event to a queue in memory. The SDK uploads the queue every 10 seconds, or when it holds 10 events. `flushEvents()` starts the upload now, and `shutdown()` stops the SDK's threads. After an upload, the JVM can take up to 60 seconds to exit, because it waits for an idle SDK thread to time out. To exit sooner, go to [Flush and shut down](https://amplitude.com/docs/sdks/analytics/java/jre-java-sdk/instrument-and-configure#flush-and-shut-down).

### Fix upload problems

To see the result of each upload, set a callback. Go to [Read the upload result](https://amplitude.com/docs/sdks/analytics/java/jre-java-sdk/verify-events#read-the-upload-result).

| Symptom | Cause | Fix |
| --- | --- | --- |
| `IllegalArgumentException: Event must have one defined userId and/or deviceId` | The `Event` constructor got `null` for both IDs. | Pass a user ID or a device ID. |
| The program never exits | The SDK sent events, and you didn't call `shutdown()`. The SDK's upload threads keep the JVM alive. | Call `flushEvents()`, then `shutdown()`, when the program finishes. |
| About 10 seconds after `shutdown()`: `Exception in thread "Thread-0" java.util.concurrent.RejectedExecutionException`, and the event never arrives | You called `shutdown()` without `flushEvents()`. `shutdown()` doesn't upload the queue, and the scheduled upload finds the threads stopped. | Call `flushEvents()` before `shutdown()`. |
| `Flush Thread Error: ... AmplitudeInvalidAPIKeyException: Amplitude Exception: Invalid API key` | The key is wrong, or belongs to a project in the other data center. | Copy the key again, and check that `setServerUrl()` matches the project's data center. |
| Callback with `400`, `Request missing required field` | The request had no API key, because `init()` received an empty or `null` key. | Check the environment variable or setting that holds your key. |
| Callback with `400`, `Invalid id length for user_id or device_id` | An ID is shorter than five characters, Amplitude's default minimum. | Use longer IDs, or [allow shorter IDs](https://amplitude.com/docs/sdks/analytics/java/jre-java-sdk/instrument-and-configure#allow-shorter-ids). |
| Callback with `408`, `Event retries exhausted.` | Every request failed before a response arrived: DNS failure, a firewall, or no outbound network. | Confirm that the host can reach `api2.amplitude.com` (or `api.eu.amplitude.com`) on port 443. If traffic must go through a proxy, go to [Route uploads through an HTTP proxy](https://amplitude.com/docs/sdks/analytics/java/jre-java-sdk/instrument-and-configure#route-uploads-through-an-http-proxy). |

## Confirm the event in Amplitude

1. In Amplitude, open **User Lookup** and search for the user ID you passed, `user-12345` in the example.
2. Open the **Activity** tab and turn on **Live event updates**.
3. Confirm that `Sign Up Completed` appears with the `plan` property.

If the event doesn't appear within a minute, follow [Verify events](https://amplitude.com/docs/sdks/analytics/java/jre-java-sdk/verify-events), which checks each stage between `logEvent()` and Amplitude's servers.

## Next steps

- Add the events and properties your tracking plan needs. Go to [Track events](https://amplitude.com/docs/sdks/analytics/java/jre-java-sdk/instrument-and-configure#track-events).
- Flush events before a job, script, or serverless function exits. Go to [Flush and shut down](https://amplitude.com/docs/sdks/analytics/java/jre-java-sdk/instrument-and-configure#flush-and-shut-down).
- Act on the result of each upload. Go to [Get upload results](https://amplitude.com/docs/sdks/analytics/java/jre-java-sdk/instrument-and-configure#get-upload-results).
- Tune batching, the Batch API, and proxies. Go to [Data delivery](https://amplitude.com/docs/sdks/analytics/java/jre-java-sdk/instrument-and-configure#data-delivery).

