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.

share|improve this question
    
Little unclear here. Is settasks.jar another file which you didn't move or is it the one you did move? – Julian Stirling Dec 15 '13 at 21:44
up vote 6 down vote accepted

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.jar

Type 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.jar

Remove the file:// and press :

java -jar /home/wilf/settask/settask.jar

If 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.

share|improve this answer
    
Yes that fixed it many thanks. Yes I was using a bash script. – user2640104 Dec 15 '13 at 21:52

I had the same problem. Starting it in the Terminal with the error

Unable to access unicentaopos.jar

The 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.

share|improve this answer
    
The OP asked for a @ startup solution and accepted a answer two years ago... – cmks Apr 7 '16 at 22:32
    
are you sure about the command CD /Desktop? cd is not CD and there is no Desktop directory in root. – Mostafa Ahangarha Apr 8 '16 at 12:38

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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