I'm trying to run a .jar file on the start up of my Linux machine (Ubuntu 12.04 server)
My script works as long as I run it inside the directory which it is in. If I try to run it outside the directory I get the error "Cannot access jarfile settasks.jar". I suppose my other script is having the same issue.
Is this possibly a script error or a permissions error? I'm completely lost and I have not found anything as of yet to resolve the issue. Any help will be welcomed.
14 Answers
Right click on the file and select Copy.
Now, say you are executing the file using this in the directory with the file in:
java -jar ./settask.jarType the beginning of the command (java -jar), and then paste -Ctrl +Shift+V - you should end up with something like this, where is specifies the full path to the file:
java -jar file:///home/wilf/settask/settask.jarRemove the file:// and press ↵:
java -jar /home/wilf/settask/settask.jarIf it works, then the same command should work in your script.
I hope this answer is OK, I think you are asking about bash scripts.
N.B:
./ tells it the command to search the directory it is currently in.
Havingfile:// at the beginning means it won't work.
I ran into Unable to access jarfile when trying to start a Spring Boot SysVinit service.
It turned out the directory and content in /srv/myapp/ had wrong ownership.
Running sudo sh -c "chown -R myapp:myapp /srv/myapp/ && chmod -R u=rx,g=,o= /srv/myapp" gave all relevant files and directories correct ownership and permissions.
I had the same problem. Starting it in the Terminal with the error
Unable to access unicentaopos.jarThe solution is more simple than the problem.
Add to the known starter the line Path=/usr/bin/unicenta/and the problem is solved.
The folder /unicenta is of course the folder where the program is.
In that way the starter looks like:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=Unicenta
Comment=Fires up Unicenta oPOS
Type=Application
Path=/usr/bin/unicenta/
Exec=/usr/bin/unicenta/start.sh
Icon=/usr/bin/unicenta/unicentaopos.ico To create the starter just CTRL+ALT+T to open the terminal.
Type cd Desktop (or Bureaublad if its Dutch) (Case sensitive)
Type nano unicenta.desktop. Copy and paste the mentioned code.
Press CTRL+O to save is. Close is by pressing CTRL+X. Type chmod +x unicenta.desktop.
Ready.
2The message "unable to access jarfile" is misleading. If you type the jarfile name incorrectly, you still get the same message not "no such file or directory". So, if you are in the directory where the jarfile is located, first, make sure that you typed the name correctly. For example, you may have a jarfile name as xxxx.1.jar; It is usual to igonre .1. and type it is xxxx.jar; you will receive "unable to access jarfile" message, which as I mentioned is misleading.
1