How to host a Java bot or app for your community
Run a Java bot or app on a panel: fat jars, Java versions, heap and container memory, secrets in environment variables, shutdown hooks, logs and updates.
Your community has a Java project: a JDA bot that runs events, a chat bridge between your game server and your Discord, or a small Spring Boot app behind your website. It runs fine from your IDE. To keep it running for everyone, it has to leave the IDE and become a jar on a server, and that move has a handful of Java-specific traps: packaging, Java versions and, above all, memory.
This guide covers hosting a general Java app for your own community or project on a panel. If you want to sell Java hosting instead, read how to start a Java app hosting business.
How a panel runs a Java app
The panel starts one JVM process, usually with a command like:
java -Xms128M -Xmx384M -jar app.jar
It runs inside a container with fixed memory, CPU and disk. The console shows standard output and standard error, the power buttons start and stop the process, and the file manager and SFTP let you upload the jar and its config.
Your IDE did a lot of quiet work for you: it put every dependency on the classpath and picked the Java version. On the server, the jar and the start command have to do all of that themselves.
Package a fat jar
A plain jar task produces a file with only your classes. Run it on a server and it fails with NoClassDefFoundError the moment it touches a dependency. You need a fat jar that bundles everything and declares its main class.
With Gradle, the Shadow plugin does this. With Maven, the Shade plugin. Spring Boot projects get it from Spring Boot's own build plugin. A minimal Maven Shade setup looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals><goal>shade</goal></goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.bot.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
Without a main class in the manifest, java -jar fails with "no main manifest attribute." Test the jar locally with exactly the command the server will use before you upload it.
A layout that works on the server:
community-bot/
app.jar
config.yml (non-secret settings)
.env (secrets, never committed)
data/
logs/Match the Java version
Java class files record which Java version they were compiled for. A jar built for Java 21 will not run on Java 17; it fails with UnsupportedClassVersionError. Two ways to stay safe:
- Run the same Java version on the server as you build with, ideally a current LTS release.
- Or compile for the server's version with the
releaseoption in your build (maven.compiler.releasein Maven, the toolchain oroptions.releasein Gradle).
Check your libraries too. Recent versions of popular libraries often require a recent Java baseline.
Memory: heap is not the whole story
This is where most hosted Java apps go wrong. -Xmx caps the heap, but the JVM also uses memory for metaspace (class data), thread stacks, the JIT code cache, garbage collector structures and native buffers. If your plan has 512 MB and you set -Xmx512M, the process can exceed the container limit and get killed, with no Java error in the console at all, just a stopped server.
Leave headroom. As a starting point, keep the heap around two thirds to three quarters of the plan's memory and watch the graph. Alternatively, let the JVM size itself relative to the container:
java -XX:MaxRAMPercentage=70.0 -jar app.jar
Two errors tell you which problem you have:
- **Process killed, no
OutOfMemoryError:** the whole JVM exceeded the container limit. Lower the heap or move to a bigger plan. - **
OutOfMemoryError: Java heap space:** the heap itself is full. Either the workload needs more heap, or something leaks.
Common leaks in community bots: caches that never evict (JDA's member cache with every intent enabled in a large server is a classic), lists of past events and listeners registered on every reload. For JDA, enabling only the gateway intents and cache flags you actually use keeps memory down considerably.
Secrets and configuration
Never compile a bot token into your jar. Jars are zip files, and anyone with the file can read every string inside it. Read secrets from environment variables:
String token = System.getenv("DISCORD_TOKEN");
if (token == null || token.isBlank()) {
System.err.println("DISCORD_TOKEN is not set");
System.exit(1);
}
If your panel does not let you set environment variables directly, keep secrets in a small .env or properties file next to the jar, read it at startup and keep it out of version control. Put non-secret settings (channel IDs, prefixes, feature toggles) in a separate config.yml so you can share that file with co-admins freely.
For JDA bots, privileged gateway intents such as Message Content and Server Members must be enabled in the Discord Developer Portal at discord.com/developers and requested in code. If a token leaks, reset it there first.
Ports for web apps
A bot that only connects out needs no port. A web app does. Spring Boot listens on 8080 by default; set it to the allocated port, for example with an environment variable:
java -Dserver.port=$SERVER_PORT -jar app.jar
Check which variable your panel uses for the allocated port, or put the number from the network section in your config. Make sure the app listens on all interfaces rather than only localhost.
Clean shutdown
When you stop or restart, the JVM receives a termination signal and runs its shutdown hooks before exiting. Use one to close connections and flush data:
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
jda.shutdown();
database.close();
}));
Spring Boot handles its own shutdown and can wait for in-flight requests if you enable graceful shutdown in its configuration.
Crash loops and logs
Java crash loops usually come from the same short list: wrong Java version, missing main class, missing dependencies, a missing environment variable or a config file not found in the working directory. The first stack trace after startup tells you which. Read the top line (the exception type and message) and the first Caused by: line; those two usually point straight at the cause.
For logs, use SLF4J with Logback or another standard backend and log to the console so the panel shows it. If you also write log files, configure rotation and a maximum history, or the logs/ folder will slowly eat your disk. Keep tokens and private messages out of every log line.
Updating
- Back up the server, including
data/and your config. - Build the new fat jar and test it locally with the server's Java version.
- Upload it under a new name, keep the old one as a fallback.
- Point the start command at the new file (or rename), restart, watch the console.
Rolling back is then a rename and a restart. For a major library upgrade such as a new JDA major version, read the migration notes and test on a separate bot application first.
Running it through a branded panel with Enzonic for Resellers
If you run Java tools next to game servers for a community, Enzonic for Resellers gives you one panel with your own name and colours for all of them. Opening a site is free, and panel-only mode serves only sign-in and the customer panel, without a storefront.
You get a live console with power controls and CPU, memory and disk stats (handy for tuning the heap), a file manager and SFTP, backups (also scheduled), scheduled tasks, subusers for co-admins and network ports. With Enzonic for Resellers, Java apps runs on your own Pterodactyl or Pelican Wings nodes today, and on Enzonic nodes where available; the plan editor shows where each plan can run. You can also connect your own Pterodactyl Wings or Pelican Wings machine. Servers you grant on Enzonic nodes have their base price charged monthly from your credits.
If your community also runs bots in other languages, see the guides for Node.js, Python and Go. Open a site to try it.
Frequently asked questions
Why does my jar say no main manifest attribute?
The jar does not declare a main class. Configure your build (Shade, Shadow or Spring Boot packaging) to set Main-Class in the manifest, then rebuild.
What causes UnsupportedClassVersionError?
The jar was compiled for a newer Java version than the server runs. Use the same Java version on both sides or compile with a lower release target.
How much heap should I give my Java bot?
Leave headroom below the plan's memory, because the JVM uses memory outside the heap. Start around two thirds to three quarters of the plan and adjust after watching the memory graph.
My server stops with no error. What happened?
Most likely the JVM exceeded the container's memory limit and was killed. Lower -Xmx or use -XX:MaxRAMPercentage, then check for leaks if memory keeps growing.