8

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.

Adam
  • 2,638

5 Answers5

13

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.

dessert
  • 39,982
Wilf
  • 30,194
  • 17
  • 108
  • 164
2

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.

Abdull
  • 502
0

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

0

I am not sure if your problem is like mine or not, but I say my problem and solution may help someone: I had this error when I wanted to run my shell script to run the Java application:

"Unable to access jar file"

my problem occurred because I had made the shell script file in Windows so the file had been created with a Windows line ending (CR) while the shell script should be with a Unix line ending (LF), so the solution was changing the line ending to Unix in the Notepadd++ and I saved file and after rerun the problem was solved.

mi_mo
  • 1
0

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.

muru
  • 197,895
  • 55
  • 485
  • 740
Johan
  • 1