Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

java    -Xmx512M\
    -DclientAppDataPath="Application Data"\
    -jar Client.jar\
    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?

I noticed error.txt contains:

blah/blah/blah/Client 2: blah/blah/blah/Client 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
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

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:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .