Bot Uptime

How to Build & Host a Java 21 JDA Bot with ShadowJar & Maven Shade

Java 21 with JDA (Java Discord API) delivers strong typing, virtual threads, and battle-tested stability for large Discord servers. The #1 mistake developers make when deploying a Java bot is uploading a "thin" JAR that does not include JDA or SLF4J inside it — resulting in immediate ClassNotFoundException errors.

1. Package a Fat/Shadow JAR with Gradle

A fat JAR (also called an uber-JAR or shadow JAR) bundles your compiled classes together with JDA and every runtime library into a single self-contained .jar file that runs anywhere with java -jar bot.jar.

build.gradle (Shadow plugin)
plugins {
    id 'java'
    id 'com.gradleup.shadow' version '8.3.0'
}

java {
    toolchain { languageVersion = JavaLanguageVersion.of(21) }
}

jar {
    manifest {
        attributes 'Main-Class': 'com.example.bot.Main'
    }
}

// Run: ./gradlew shadowJar
// Upload: build/libs/your-bot-1.0-all.jar -> rename to bot.jar

2. Right-Sizing JVM Memory for Container Hosting

Unlike Node.js or Rust, the JVM reserves off-heap metaspace and thread stacks on top of your Java heap. On a 256 MB Free container, stick to lightweight JDA bots and avoid heavy Spring Boot frameworks; for medium-to-large Java bots using LavaPlayer, Hibernate, or heavy caching, Developer (2 GB RAM · 100% CPU) or Pro (6 GB RAM · 200% CPU) gives the JVM plenty of breathing room without GC pauses.

Disable unused JDA caches via JDABuilder.createLight(token) when you do not need full member/voice caching — this alone can cut JVM RAM consumption in half.

Main.java (Lightweight JDA 5 startup)
public class Main {
    public static void main(String[] args) throws Exception {
        String token = System.getenv("DISCORD_TOKEN");
        if (token == null || token.isBlank()) {
            throw new IllegalStateException("Missing DISCORD_TOKEN environment variable");
        }
        JDABuilder.createLight(token)
            .addEventListeners(new CommandListener())
            .build()
            .awaitReady();
    }
}

Frequently Asked Questions

Why do I get "no main manifest attribute, in bot.jar"?

Your build script did not declare Main-Class in the JAR manifest. Add manifest { attributes "Main-Class": "your.package.Main" } and rebuild with ./gradlew shadowJar.

Which Java version do containers run?

Bot Uptime Java containers run modern Java 21 LTS, supporting records, pattern matching, and virtual threads out of the box.

Ready to deploy your bot 24/7?

Launch a custom Discord, Telegram, or WhatsApp container (Python, Node.js, Java, Rust) with Managed Databases and Free AI Agents — or deploy a ready-made Discord bot in 1 click on Bot Uptime.