This is my case. I have a .war that I execute with java and it only works inside its folder:
cd /opt/myappdir/
java -jar myapp.war
Note: It does not work like that:
java -jar /opt/myappdir/myapp.war
I have created a bash script (sudo /opt/myappdir/run.sh
) to launch this command
#!/usr/bin/env bash
cd /opt/myappdir/
java -jar myapp.war
So far everything works. Now the problem:
I want to launch it from a shortcut on my desktop. This is my desktop shortcut to start myapp war
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=MyApp
Comment=Run MyApp
Type=Application
Exec=/opt/myappdir/run.sh
Icon=/opt/myappdir/myapp.ico
Path=/opt/myappdir/
Terminal=false
But since myapp.war
needs to be run with sudo and inside the myappdir
I modified my run.sh
script as follows
#!/usr/bin/env bash
cd /opt/myappdir/
dir=$(dirname $(readlink -m $BASH_SOURCE))
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY QT_X11_NO_MITSHM=1 java -jar myapp.war
Why line with dir=$(dirname $(readlink -m $BASH_SOURCE))
?
because I need to make sure myapp.war
is running inside myappdir
Why line with pkexec
?
because when double clicking the desktop shortcut java
needs to be run with sudo
out:
Error: Unable to access jarfile myapp.war
someone Here offers a solution to a similar question, but it didn't work for me. (Modifying the proposal:)
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=java -jar 'myapp.war'
Path=/opt/myappdir/
Name=myapp
Comment=myapp
Icon=/opt/myappdir/myapp.ico
how can i fix my run.sh
script to run myapp.war
with sudo
inside myappdir
, and call it from desktop shortcut? Thanks
Update
According to what someone explains HERE, pkexec
does not run in the same directory (I guess that's the reason why it can't find myapp.war
file). So the solution could be to run a command that would force it into the directory to run java, but I've tried and failed
0 Answers