Put your Discord bot online with Java (JDA)

Put your JDA bot online 24/7: build a jar with all dependencies using Gradle or Maven, keep your token in .env, set JAR FILE and Java version, fix errors.

EliteStarHosting Team8 November 20264 min read
Ready to start? View the Discord Bot Hosting plans

This is how you put a bot in Java with JDA online day and night. JDA works with Java 8 and newer. Use at least 6.7.0, the newest version in November 2026: it already handles the hidden channels (channel obfuscation) that Discord introduces for all bots on 16 November 2026.

Your server has to run on Java: under Startup you then see the JAR FILE field. Do you see MAIN FILE or APP PY FILE? Then ask us through support to switch it. Create your bot and token as in step 1 of the guide for Node.js.

1. Your code and your token

The Java server has no field for your token, so put it in a .env file that your bot reads, with one line: DISCORD_TOKEN= followed by your token. A simple src/main/java/Bot.java:

import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;

import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.requests.GatewayIntent;

public class Bot extends ListenerAdapter {
    public static void main(String[] args) throws Exception {
        Properties env = new Properties();
        try (Reader in = Files.newBufferedReader(Path.of(".env"))) {
            env.load(in);
        }
        JDABuilder.createLight(env.getProperty("DISCORD_TOKEN", "").trim())
                .enableIntents(GatewayIntent.MESSAGE_CONTENT)
                .addEventListeners(new Bot())
                .build();
    }

    @Override
    public void onMessageReceived(MessageReceivedEvent event) {
        if (event.getMessage().getContentRaw().equals("!ping")) {
            event.getChannel().sendMessage("Pong!").queue();
        }
    }
}

MESSAGE_CONTENT is a privileged intent: also turn on the Message Content Intent in the Developer Portal. For GUILD_MEMBERS that is the Server Members Intent, for GUILD_PRESENCES the Presence Intent. Slash commands work without intents. Never put .env in Git: this is how you keep your token safe.

2. Build a jar with all dependencies

The server starts your bot with java -jar, so JDA must be inside your jar. Build with JDK 21 or newer and compile for Java 21, the newest Java on the server. With Gradle and the Shadow plugin (9.6.1 needs Gradle 9.2 or newer), build.gradle.kts looks like this:

plugins {
    application
    id("com.gradleup.shadow") version "9.6.1"
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("net.dv8tion:JDA:6.7.0")
}

application {
    mainClass = "Bot"
}

tasks.withType<JavaCompile>().configureEach {
    options.release = 21
}

tasks.shadowJar {
    archiveFileName = "bot.jar"
}

./gradlew shadowJar (on Windows gradlew.bat shadowJar) then creates build/libs/bot.jar.

Using Maven? In your pom.xml, add JDA (net.dv8tion:JDA:6.7.0) to your dependencies, <maven.compiler.release>21</maven.compiler.release> to <properties> and the Shade plugin to <build>:

<finalName>bot</finalName>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.6.2</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals><goal>shade</goal></goals>
        <configuration>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>Bot</mainClass>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

mvn package creates target/bot.jar. Upload that one, not original-bot.jar.

3. Upload and set up Startup

  1. In the game panel, go to Files and upload bot.jar to the main folder with Upload and Upload Files, or through SFTP.
  2. In the same folder, create your .env with New file.
  3. Under Startup, enter the name of your jar at JAR FILE, such as bot.jar. This field takes 20 characters at most.
  4. At Docker Image, choose ghcr.io/parkervcp/yolks:java_21.
  5. Click Start and open Console. Once you see Finished Loading!, your bot is online.

The Upload menu with Upload Files, Upload Folders and Upload from URL

The Using fallback logger warning is harmless. To update, upload your new jar and click Restart.

Common errors

  • Unable to access jarfile: JAR FILE (case-sensitive) is wrong, or the jar isn't in the main folder.
  • no main manifest attribute: your jar has no Main-Class. Check mainClass or the ManifestResourceTransformer.
  • NoClassDefFoundError with net/dv8tion/jda: you uploaded the jar without dependencies.
  • UnsupportedClassVersionError: your jar was built for a newer Java, such as Java 25 (class file version 69.0). Compile for Java 21.
  • NoSuchFileException: .env or Token may not be empty: .env isn't in the main folder or lacks the DISCORD_TOKEN= line.
  • The provided token is invalid!: create a new token with Reset Token.
  • Disallowed intents: turn on the intent your code asks for in the Developer Portal.
  • OutOfMemoryError: Java heap space: the server starts Java without -Xmx, so your bot's heap may only use a quarter of the memory. Choose a bigger plan.