Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What I'm trying to achieve is to run a java program on any Linux system (Ubuntu, Fedora, etc... covering as much as possible) by simply double clicking a file-like I would on Windows.
I have created a .sh file(and granted execute permissions) with the following content:

#!/bin/sh
java    -Xmx512M\
    -Djava.library.path="."\
    -DclientAppDataPath="Application Data"\
    -jar Client.jar\
    Phoenix.client.ClientMain\
    1>output.txt 2>error.txt

If I try to execute this file using the Ubuntu Terminal it works fine. However when I try to double click the file and choose Run or Run in Terminal, I see nothing. Apparently the shell opens and closes immediately. How do I avoid this?

EDIT:
I noticed error.txt contains:

blah/blah/blah/Client Launcher.sh: 2: blah/blah/blah/Client Launcher.sh: java: not found

I have extracted a jdk1.x.x.tar.gz and added java home to PATH manually using .bashrc file. Could this be the cause? How can I fix it?

share|improve this question
2  
Try using the full path to java. –  pjc50 Sep 9 '13 at 14:20
    
@pjc50, Damn! It worked. That doesn't solve my problem in general (a setup program generates this file), but at least I'm sure of what's going on. –  atoMerz Sep 9 '13 at 14:26
    
If you don't use a locally installed (i.e. not installed by the package management) version of java, your script does not know where it is located. .bashrc is only evaluated when you log into an interactive session. –  Tim Sep 9 '13 at 14:30

1 Answer 1

There's a nice solution which causes Java jar files to be treated as an executable without requiring shell scripts, although it's a little fiddly to set up:

https://wiki.archlinux.org/index.php/Binfmt_misc_for_Java

I believe that popular distros have packages that will sort it out for you, although I've not used it myself recently.

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.