# Java

## 1.  Installing java-SDK package

HyperTest's Maven packages are hosted on a GitHub public Maven registry.\
To install and use HyperTest's `java-sdk` package in your application, follow these steps:

1. Create MVN\_TOKEN - The Hypertest Team may share this with you, or you can generate your own personal access token by visiting [GitHub Personal Access Tokens](https://github.com/settings/tokens).
2. Add Repository Configuration in `pom.xml`
   1. Define Properties in `pom.xml` file
   2. Add the Repository in  `pom.xml` file
3. Add the HyperTest agent dependency to your project. You can check for the latest version on the [HyperTest Java SDK](https://central.sonatype.com/artifact/co.hypertest/hypertest-agent/versions).
4. Install HyperTest's java-sdk package

Add the following content in your `pom.xml`

<details>

<summary>pom.xml</summary>

```xml
<dependencies>
    .
    .
    .
    
    <dependency>
        <groupId>co.hypertest</groupId>
        <artifactId>hypertest-agent</artifactId>
        <version>0.1.13-alpha.43</version>
    </dependency>
</dependencies>

<properties>
    <MVN_USERNAME>hypertestcustomers/[YOUR_GITHUB_USERNAME]</MVN_USERNAME>
    <MVN_TOKEN>[YOUR_MVN_TOKEN]</MVN_TOKEN>
</properties>

<repositories>
    <repository>
        <id>github</id>
        <url>https://${MVN_USERNAME}:${MVN_TOKEN}@maven.pkg.github.com/hypertestco/autoqa_v2_java</url>
    </repository>
</repositories>
```

</details>

We support multiple package manager&#x20;

1. Maven
2. Gradle
3. Bazel

To run with maven

```bash
mvn clean install
```

To run with gradle

```gradle
./gradlew build
```

To run with bazel

```python
bazel run //:<YOUR-APPLICATION-MODULE>
```

## 2.  Initializing SDK

#### &#x20;2.1 Adding SDK in code

* Initalize the HyperTest Java SDK in the `public static void main` method of your service. This must be the first thing in your main method.
* \<HT\_SERVICE\_ID> is the identifier that we created in [**Adding your first service section**](/setup-guide/readme/adding-your-first-service.md)

{% hint style="warning" %}
This needs to happen as early in your app as possible.
{% endhint %}

```typescript
new HypertestAgentBuilder("<HT_SERVICE_ID>", "<YOUR_SERVICE_NAME>",  "<API_KEY>",
 "<LOGGER_URL>", "<APPLICATION_CLASS>").build();
```

#### 2.2 Mark app as ready

Call this method after `SpringApplication.run` when the app is ready to receive traffic, it indicates that tests can be started (This is important ONLY FOR REPLAY mode).

```javascript
// Rest Application code...
System.setProperty(APP_STATUS, UP_STATUS);
```

To enable hypertest, set the `HT_MODE` env variable to `RECORD` and start your app

## 3. Verifying traffic is captured

Start sending http requests on your app running with hypertest sdk.

You should start seeing requests under All requests section on the dashboard

<figure><img src="/files/krogi7xn6W8mvMdR4l2e" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: 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:

```
GET https://docs-v2.hypertest.co/setup-guide/readme/integrate-sdk/integrate-java-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
