Updated 30 November 2026
A Discord bot written in Java, with JDA, Javacord or Discord4J, does not run on our Discord bot hosting plans: those plans run Node.js or Python, and Java is not installed there. A Java bot runs on a VPS, where you install Java yourself and keep the bot online 24/7 with systemd. This guide shows what to pick and how to set it up.
Which option fits your bot?
- Your bot is in Java (JDA, Javacord, Discord4J) or you run Lavalink yourself: a VPS. You get root access and can install any Java version.
- You can choose the language: discord.js or discord.py run on the bot plans without any server work, with packages installed for you and code from GitHub. See discord.js bot hosting and Python Discord bot hosting.
- A music bot in Node.js or Python that uses Lavalink: the bot can run on a bot plan and connect to a Lavalink server elsewhere. See Discord music bot hosting with Lavalink.
Run a JDA bot on a VPS
- Build one jar with all dependencies, for example with the Gradle Shadow plugin (
./gradlew shadowJar) or the Maven Shade plugin. Test it on your PC withjava -jar bot.jar. - Install Java on the VPS. On Ubuntu 24.04:
sudo apt install openjdk-21-jre-headless. Use the Java version your build targets; JDA 5 needs Java 8 or newer. - Make a user and folder:
sudo useradd -r -m -d /opt/mybot mybot, then copybot.jarto/opt/mybot(for example withscp). - Store the token in
/opt/mybot/.envasDISCORD_TOKEN=your-token, readable only by the bot user (chmod 600). In your code read it withSystem.getenv("DISCORD_TOKEN"). - Make a systemd service in
/etc/systemd/system/mybot.service:[Unit] Description=My Discord bot After=network-online.target [Service] User=mybot WorkingDirectory=/opt/mybot EnvironmentFile=/opt/mybot/.env ExecStart=/usr/bin/java -Xmx512m -jar /opt/mybot/bot.jar Restart=always RestartSec=5 [Install] WantedBy=multi-user.target - Start it:
sudo systemctl daemon-reloadandsudo systemctl enable --now mybot. The bot now starts again after a crash or a reboot. Logs:journalctl -u mybot -f.
-Xmx sets the most memory Java may use. A typical JDA bot is fine with 256 to 512 MB; raise it for big caches or many servers, and leave room for the operating system.Updating your bot
Build a new jar, copy it over the old one and run sudo systemctl restart mybot. Want updates from GitHub? Clone the repository in /opt/mybot, and build and restart with a short script after git pull. The same steps for Node.js and Python bots are in Run a Discord bot 24/7 on a VPS with systemd.
Frequently asked questions
Can I host a JDA bot on a ServerSpark bot hosting plan? No. The bot plans run Node.js or Python and Java is not installed there. Use a VPS for a Java bot.
How much memory does a JDA bot need? A typical bot runs with 256 to 512 MB for Java. Bots in many servers or with large member caches need more.
Which Java version should I use? The one your project is built for. Java 21 is a long-term support version that works with current JDA releases.
How do I keep a Java Discord bot online 24/7? Run it as a systemd service with Restart=always, so it starts again after a crash and after a reboot.