Skip to main content

Deploy Java Apps

Java is a programming language popularly used globally. Java is served as a compiled language, which means you need to compile your code before running it.

There is no default java compiler at system level. You have to install it first through deployment scripts.


Serving Java apps requires to be run via GLS, that's mean you have to listen from given PORT env/args.


The deployment script below installs the latest java compiler and writes and run it directly.
source: clear
- java
root: public_html/public
enabled: "on"
app_start_command: env PORT=$PORT java
- filename:
content: |


public class Main {
public static void main(String[] args) throws Exception {
String portStr = System.getenv("PORT");
int port = portStr == null ? 3000 : Integer.parseInt(portStr);
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
System.out.println("Server is listening to localhost:" + port);
server.createContext("/", new DefaultHandler());
server.setExecutor(null); // creates a default executor

class DefaultHandler implements HttpHandler {
private static String template = """
<!DOCTYPE html>
<title>Java App</title>
<link rel="stylesheet" href="//">
<body class="p-5 text-center">
<p><img src="//"
class="img-fluid rounded-circle"></p>
<h1 class="mb-3">Hello, world!</h1>
<p>Serving from Java version %s</p>
<p class="text-muted">DOM Cloud</p>

public void handle(HttpExchange t) throws IOException {
String version = Runtime.version().toString();
String response = String.format(template, version);
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();

Existing Java projects

Existing Java projects can run directly from source code. This eliminates the need to compile the code into a JAR file, although startup time may be a little bit slower to start.
- java
root: public_html/public
enabled: "on"
app_start_command: env PORT=$PORT java

Use other Java versions

To switch Java version use feature syntax like java latest, java 18, etc. Check your current Java version using java --version in SSH.

- java 18

Java installation binaries is used from Adoptium Project. Only latest build from them in each major version (as low as jdk 8) is available to download using this feature.

App Management

Your app do not restarted automatically after file changes. To restart, run restart via SSH.

Environment variables can be set either using NGINX's env_var_list or ~/.bashrc. Usually your language framework also reads .env files.

See NGINX and App Daemon for more information about NGINX and App managements including restarting, environment variables, and other global limitations.

App Logging

You can see app log from Check -> Check Process Logs tab. Only startup problems displayed in the browser.

Please use a proper logging mechanism such as log4j then write it to a log file, or any other solution that suits you.

NGINX errors and traffic logs can be examined via Webmin or Check -> Check Process Logs tab.