In this article, we will address a common issue faced by many Java/Minecraft server administrators on Ubuntu: the “Could not find or load main class” error. This error often arises due to a simple typographical mistake in the command line, and we will guide you through the process of fixing it.
To fix the "Could not find or load main class" error in Java/Minecraft Server on Ubuntu, ensure that you are using a minus sign instead of a hyphen in the command line. Replace the hyphen with a minus sign and run the command again. Additionally, make sure to specify the initial and maximum heap size for the Java Virtual Machine (JVM) using the
-Xmx options respectively. Adjust these values according to your system’s RAM limits.
Understanding the Error
The error “Could not find or load main class â€“Xms1024M” typically occurs because a hyphen
â€“ is used instead of a minus
- in the command. Java interprets
â€“Xms1024M as the name of the class or file, rather than an option.
Correcting the Command
To fix this, replace the hyphen with a minus sign and run the command again:
sudo java -Xms1024M -Xmx1024M -jar minecraft_server.1.9.2.jar nogui
In this command,
-Xmx1024M are options that set the initial and maximum heap size for the Java Virtual Machine (JVM) respectively. The values are set to 1024MB, but you can adjust these according to your system’s RAM limits. The
-jar option is used to specify the JAR file that contains the application to be run, which in this case is
nogui option is used to run the server without a GUI.
Specifying RAM for the Minecraft Server
Not specifying the RAM can cause your Minecraft server to crash if it doesn’t have enough reserved RAM. Adjust the
-Xms (initial heap size) and
-Xmx (maximum heap size) values according to your system’s RAM limits.
Running the Minecraft Server in the Background
There are several methods to start the Minecraft server via SSH and let it run in the background after disconnecting:
screen: Run the command
screenfollowed by your start command. Press
Dto detach from the screen session. To resume the session, run
fg: After starting the Minecraft server, press
Zto suspend the process. Then type
bgto run it in the background. To bring it back to the foreground, use the
nohup: Prepend your start command with
nohup. After starting the server, you can close your SSH session, and the server will continue running. To prevent excessive log file creation, append
>/dev/null 2>&1to the end of the command.
- Using initscripts: Initscripts allow your server to auto-start/stop on boot or manual invocation. However, setting up initscripts can be complex and system-specific. Search online for instructions tailored to your system.
Fixing Permission Errors
Regarding the permission errors you encountered, it seems that Minecraft created files with root ownership, preventing access. To fix this, run the command
sudo chown -R $USER:$USER . in the Minecraft folder to change ownership to your user.
In conclusion, the “Could not find or load main class” error in Java/Minecraft Server on Ubuntu can be easily fixed by ensuring the correct use of command line options and properly setting up the server. We hope this guide has been helpful in resolving this issue.
In the command line, a hyphen (-) is used to indicate command line options or arguments, while a minus sign (–) is not recognized as a valid character and can cause errors.
To adjust the RAM settings for your Minecraft server, you need to modify the
-Xms (initial heap size) and
-Xmx (maximum heap size) values in the command. These values determine the amount of RAM allocated to the server. Make sure to set them according to your system’s RAM limits.
There are several methods to run the Minecraft server in the background after disconnecting from SSH. You can use tools like
nohup to achieve this. Another option is to suspend the process using
Z and then run it in the background using the
bg command. Each method has its advantages and disadvantages, so choose the one that suits your needs best.
If you encounter permission errors in the Minecraft folder, you can fix them by running the command
sudo chown -R $USER:$USER . in the Minecraft folder. This command changes the ownership of the files and folders in the Minecraft directory to your user, allowing you to access and modify them.
Setting up initscripts for your Minecraft server can be complex and system-specific. It involves creating a custom script that specifies how the server should start, stop, and interact with the system’s init system. Detailed instructions for setting up initscripts can be found online, tailored to your specific operating system and version.