> ## Documentation Index
> Fetch the complete documentation index at: https://docs.minimus.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Java Tutorial

> How to build more secure Java apps using OpenJDK and OpenJRE

This project provides a test framework for validating a multi-stage build for a Java application with TLS enabled.

The setup includes the creation of self-signed certificates and has the Java container run an application server over HTTPS.

<Steps>
  <Step title="Fetch the files below from our GitHub repository">
    Save these files to your project folder:

    * [certgen.sh](https://github.com/minimusio/examples/blob/main/jdk-jre/certgen.sh)
    * [create-certs.yml](https://github.com/minimusio/examples/blob/main/jdk-jre/create-certs.yml)
    * [docker-compose.yml](https://github.com/minimusio/examples/blob/main/jdk-jre/docker-compose.yml)
    * [Dockerfile.app](https://github.com/minimusio/examples/blob/main/jdk-jre/Dockerfile.app)
    * [Server.java](https://github.com/minimusio/examples/blob/main/jdk-jre/Server.java)
  </Step>

  <Step title="Generate the certificates">
    Run the following command to generate the certificates.

    ```
    docker compose -f create-certs.yml up --abort-on-container-exit
    ```
  </Step>

  <Step title="Start the Java server">
    This will run the Java server and map port 5001 on your host to 5001 in the container.

    ```
    docker compose up --build app
    ```
  </Step>

  <Step title="Extract the certificate for curl">
    You need to place the server certificate (https.crt) on your host so you can communicate with curl.

    Copy it from the container Docker volume to your host (The container name in our example is `jdk-jre-tls-test-app-1`):

    ```
    docker cp jdk-jre-tls-test-app-1:/certs/https.crt ./https.crt
    ```
  </Step>

  <Step title="Test with curl">
    Now you can send curl requests to your Java server.

    * Send a curl command to the default endpoint to get a text response:

      ```bash theme={null}
      curl --cacert ./https.crt https://localhost:5001/
      ```

      You should get the following response:

      ```
      ✅ Hello over HTTPS from Java TLS Server running minimus images!
      ```
    * Send a curl command to the JSON endpoint:

      ```bash theme={null}
      curl --cacert ./https.crt https://localhost:5001/data
      ```

      You should get the following response:

      ```json theme={null}
      {
      "message": "Hello from the server running minimus image and using json format!",
      "status": "success"
      }
      ```
  </Step>
</Steps>
