its_simon
its_simon

Reputation: 31

Is there a way to execute a .jar file through a shell script? (Raspbian)

In gerneral

Mission

I want to run java -jar -Xmx2G -Xms2G /home/pi/minecraft/server/spigot-1.15.2.jar by clicking a desktop icon (or .desktop file).
When I type the commant into a terminal it works.

Problem

The Terminal crashes.

What i've tried

I created a .desktop File which executes a .sh file.
My .desktop File:

[Desktop Entry]
Version=1.0
Name=Spigot
Comment=
Exec=/home/pi/Desktop/launch_spigot_server.sh
Icon=/home/pi/Pictures/spigot.png
Terminal=true
Type=Application
Categories=Utility;Application;
X-KeepTerminal=true

My .sh File:

#!/bin/bash
pkexec java -jar -Xmx2G -Xms2G /home/pi/minecraft/server/spigot-1.15.2.jar

("pkexec" because I think I need sudo rights to run a .jar file)

Result

The Terminal actually opens and executes the .jar file and it says Loading libraries, please wait..., then throws some sort of Error and instantly crashes.

That is the farthest i've come in 3 hours.

Upvotes: 0

Views: 640

Answers (1)

its_simon
its_simon

Reputation: 31

First go to the directory and then execute the java -jar... command

#!/bin/bash
cd /home/pi/minecraft/server/
java -jar -Xmx2G -Xms2G spigot-1.15.2.jar

Upvotes: 2

Related Questions