0

I have a runnable .jar file, which i can run from my linux terminal but I need to run that .jar file using a .sh file.

#!/bin/bash
java -jar executer.jar

If i double click the .sh file, terminal opens up but my code doesn't get executed. Kindly let me know, whats wrong.

lokesh
  • 49
  • 10
  • If you run this script from terminal everything works? – talex Nov 09 '18 at 07:18
  • may be try this https://askubuntu.com/questions/138908/how-to-execute-a-script-just-by-double-clicking-like-exe-files-in-windows – Ryuzaki L Nov 09 '18 at 07:18
  • More specifically, can you run the java line in a bash terminal? – Roy Shahaf Nov 09 '18 at 07:19
  • If i try to run the .sh file from terminal am getting the following error "Unable to access jarfile/executer.jar" – lokesh Nov 09 '18 at 07:21
  • @RoyShahaf Yes, using terminal i can run the java line alone. it's working fine. But if i try to run the script, above error is displayed. – lokesh Nov 09 '18 at 07:24
  • Is the script in the same folder as the jar? – Roy Shahaf Nov 09 '18 at 07:27
  • At any rate this looks similar to https://stackoverflow.com/questions/11943948/what-causes-unable-to-access-jar-file-error . Try moving both script and the jar into a different folder (or using chmod to alter the permissions) – Roy Shahaf Nov 09 '18 at 07:29

3 Answers3

1

Try moving into sh file location using terminal and try to execute it using following command.

 ./startup.sh 

If your file name is 'startup'

Sandunka Mihiran
  • 556
  • 4
  • 19
0

Try to execute a command to output a log file.

Then check the log info.

java -jar executer.jar >err.log 2>1

BSMP
  • 4,596
  • 8
  • 33
  • 44
0

As the question is about "double clicking", try passing the complete path to java and give executable permissions (sudo chmod +x <shfile.sh>)

I got a situation like yours and logging the error to a log file, like Henry He's answer, told me that java wasn't found. Even though I can run from the terminal, I got a java: command not found

As my java bin comes from adsf (The Multiple Runtime Version Manager) I passed the complete path and it worked:

#!/bin/bash
<complete-path-to-java> -jar executer.jar