This is an example of how to set up a Java application to deploy on Kinsta’s Application Hosting services from a GitHub repository.

During the deployment process, Kinsta automatically installs dependencies defined in your pom.xml file. You must ensure your main class is defined in the pom.xml file.

  1. Log in to GitHub and create a new repository from this template (Use this template > Create a new repository): Kinsta – Hello World – Java
  2. In MyKinsta, add an application with the Hello World Java repository. The Start command can be left blank for the web process as Kinsta automatically detects the required command during the first deployment.

The app is available as soon as the build finishes and a Hello World page loads at your application’s URL.

Java Hello World page after successful installation.
Java Hello World page after successful installation.

Web Server Setup

Port

Kinsta automatically sets the PORT environment variable. You do not need to define it or hard-code it into the application. Use System.getenv("PORT") in your code when referring to the server port.

Start Command

When you deploy an application, Kinsta automatically creates processes based on the Procfile in the root of the repository. This repository includes the following command to run the server:
web: java -jar target/kinsta-java-hello-world-1.0-SNAPSHOT.jar