> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.squarecloud.app/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How to host a Spring Boot application (Java)

# How to Host Spring Applications on Square Cloud

Spring Boot has made life easier for Java developers by embedding the server (such as Tomcat) directly into the executable file. To run your application on Square Cloud, the focus must be on network configuration and generating the correct artifact.

---

## 1. Configuring the Port (Port 80)

Unlike the local environment where we usually use port 8080, Square Cloud requires your application to listen on **port 80**. 

You can configure this in two ways:

### Via Properties File:
In your `src/main/resources/application.properties` file:
```properties
server.port=80
```

Or, if you prefer YAML (`application.yml`):
```yaml
server:
  port: 80
```

### Via Environment Variables (Recommended):
You can also leave the default port in the code and define an **ENV** variable in the Square Cloud dashboard:
*   **Name:** `SERVER_PORT`
*   **Value:** `80`

---

## 2. Packaging the Application (JAR)

Square Cloud executes Java applications through **JAR (Java Archive)** files. You must generate an "Uber JAR" (or Fat JAR), which contains all the necessary dependencies inside a single file.

### Using Maven:
Run the command at the root of the project:
```bash
./mvnw clean package
```

### Using Gradle:
Run the command at the root of the project:
```bash
./gradlew build
```

The generated file will be in the `target/` folder (Maven) or `build/libs/` folder (Gradle).

---

## 3. Preparing the Deployment

For submission, we recommend creating a `.zip` file containing:
1.  Your `.jar` file (e.g., `my-api-1.0.0.jar`).
2.  External configuration files (if any).

**Note:** It is not necessary to send the source code (`src/`), only the compiled artifact.

---

## 4. Monitoring Tips

*   **Logs:** Spring Boot generates detailed logs. Follow them in the Square terminal to identify dependency injection errors or database connection failures.
*   **Health Checks:** If you are using **Spring Boot Actuator**, you can monitor your application's health in real time.