> For the complete documentation index, see [llms.txt](https://govplane.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://govplane.gitbook.io/docs/documentation/getting-started/quickstart-1/java.md).

# Java

{% hint style="warning" %}
Before proceeding with these steps, read the initial steps of the quick start guide here [Quickstart](/docs/documentation/getting-started/quickstart-1.md)
{% endhint %}

### 1. Add the SDK dependency

In your Maven project, add the Govplane Runtime SDK to your `pom.xml`:

```xml
<dependency>
    <groupId>com.govplane</groupId>
    <artifactId>gp-runtime-sdk</artifactId>
    <version>0.1.1</version>
</dependency>
```

{% hint style="info" %}
For other SDKs, please review the instructions in the SDK Overview section.
{% endhint %}

***

### 2. Initialize the client

Initialize the client using your Runtime Key and Base URL:

```java
import com.govplane.sdk.client.RuntimeClient;
import com.govplane.sdk.client.RuntimeClientConfig;
import com.govplane.sdk.types.RuntimeBundleV1;

RuntimeClientConfig config = RuntimeClientConfig
        .builder(
            System.getenv("GP_BASE_URL"),
            System.getenv("GP_RUNTIME_KEY")
        )
        .pollMs(5_000)
        .build();

RuntimeClient<RuntimeBundleV1> client = new RuntimeClient<>(config);
client.start();
client.warmStart(); // blocks until the first policy bundle is received
```

{% hint style="warning" %}
Make sure `GP_BASE_URL` and `GP_RUNTIME_KEY` are securely stored as environment variables and never hard-coded in source code.
{% endhint %}

***

### 3. Implement your first policy evaluation

You can now evaluate a policy from your application:

```java
import com.govplane.sdk.types.Decision;
import com.govplane.sdk.types.Target;

import java.util.Map;

Target target = new Target("api", "your-resource", "your-action");

Map<String, Object> context = Map.of(
    "userId", "123",
    "role",   "admin"
);

Decision decision = client.evaluate(target, context);

switch (decision) {
    case Decision.Allow a  -> System.out.println("Allowed — rule: " + a.ruleId());
    case Decision.Deny d   -> System.out.println("Denied — reason: " + d.reason());
    default                -> System.out.println("Decision: " + decision.decision());
}
```

The evaluation response contains the final effect (`Allow`, `Deny`, `KillSwitch`, `Throttle`, or `Custom`) and additional metadata such as the matched policy key and rule ID.

***

### 4. Run and verify

Start your application and:

1. Trigger your evaluation logic
2. Check your logs
3. Confirm the returned effect matches your expected outcome

If everything is working correctly, your first Govplane-powered governance check is live.

{% hint style="success" %}
`client.evaluate()` runs entirely in-process against a locally cached policy bundle — no HTTP call is made per evaluation. Latency is sub-millisecond.
{% endhint %}

***

### 5. Clean up

When your application shuts down, stop the client to release background threads:

```java
client.flushTraces().get(); // drain any pending trace events
client.stop();
```

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://govplane.gitbook.io/docs/documentation/getting-started/quickstart-1/java.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
