0

Double-Click just opens it as a archive.

So what is the solution to run a Jar file under Ubuntu 17.10. If I right-click and select find application, Java 8 does not show up?

&>java -version
openjdk version "1.8.0_144"
OpenJDK Runtime Environment (build 1.8.0_144-8u144-b01-2-b01)
OpenJDK 64-Bit Server VM (build 25.144-b01, mixed mode)
1

From your username, I'm going to assume you're trying to run a dedicated server, and will post my answer as such. This system has been battle-tested and is currently being used by a network where I am the infrastructure admin (alongside other fancy features), as well as countless other entry-level servers and production networks.

If you want a persistent auto-restarting server, you might look at creating a systemd service for your server. You will lose your GUI and headless interface, but you'll still be able to issue commands to your server through RCON or similar.

Effectively, you'd need to create a new user (let's call it mcserver) that will handle your server tasks:

sudo adduser --system --disabled-login --group --home /opt/mcserver 

Next, you'll want to switch to this user:

sudo -u mcserver
cd /opt/mcserver

While you're here, copy all of your game server files and whatever over.

Next, create a new script to launch your server. Do not include any relaunch logic or similar. It should be very simple:

#!/bin/bash
/usr/bin/java -Xms1024M -Xmx4G -jar -XX:+UseConcMarkSweepGC -jar minecraft.jar --nojline --noconsole

Mark the file as executable using chmod +x mcserver.sh.

You can exit the session for mcserver, you won't need it anymore.

Create a new file (mcserver.service) in /etc/systemd/system:

sudo nano /etc/systemd/system/mcserver.sh

In this file, add the following contents:

[Unit]
Description=Vanilla Minecraft Server

Wants=network.target
After=network.target

[Service]
User=mcserver
Group=mcserver

ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
PrivateTmp=true
InaccessibleDirectories=/root /sys /srv -/opt /media -/lost+found
ReadWriteDirectories=/var/minecraft/server
WorkingDirectory=/var/minecraft/server    

Restart=on-failure
RestartSecs=5

ExecStart=/opt/mcserver/mcserver.sh

[Install]
WantedBy=multi-user.target

Once you're done, you'll need to activate the service:

sudo systemctl daemon-reload
sudo systemctl enable mcserver.service
sudo systemctl start mcserver.service

The server will now auto-start on system boot, and run normally.

Note that the server will auto-restart on a failure (non-zero exit code), so /stop will stop the server without the chance for a respawn. While you may also stop the server with systemctl stop mcserver.service, it'll be unsafe as the server will not get to gracefully die. You can, however, use rcon to have the aforementioned command send a graceful stop. This, however, will be left as an exercise to the reader.

Backup scrips can still be run, though it would be advisable to use a user cron-entry that ZIPs the entire folder, and stores it somewhere safe.

  • This post was about running the Minecraft Game Jar. In 16.10 you could right-click and open with Java but in 17.10 that option has been removed. Very Impressive post though! – EODCraft Staff Nov 10 '17 at 10:23
  • @Renato A. had the solution I was looking for. – EODCraft Staff Nov 10 '17 at 10:30
  • I think this is a good tutorial for marking a mc server. kudos for you admin – Egon Stetmann. Nov 10 '17 at 14:12
0

I did make a script like running my server but there must be a better way. Also, not very elegant, just typing java -jar MC.jar in terminal, both ways leave an open terminal.

#!/bin/sh
while true
do
java -Xms1024M -Xmx4G -jar -XX:+UseConcMarkSweepGC -jar MC.jar
echo "If you want to completely stop the server process now, press 
Ctrl+C before the time is up!"
echo "Rebooting in:"
for i in 5 4 3 2 1
do
echo "$i..."
sleep 1
done
echo "Rebooting now!"
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.