Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: How can i make java program executable?

  1. #1
    Join Date
    Jan 2006
    Beans
    38

    How can i make java program executable?

    Hi. Ok, I have created a jar file for my java program. I just only want to ask how can i make that jar file executable when it is double clicked? Or, if that can't be done with jar, is there any other method of doing it so? And also, how can i include or put that java program under Applications > Games menu?

    Thanks....

  2. #2
    Join Date
    Feb 2005
    Location
    Sydney, Australia
    Beans
    375
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: How can i make java program executable?

    You run them with the command 'java -jar file.jar', you could write a shell script to run it. Open up gedit (or your favourite text editor), and put this in it:
    Code:
    #!/bin/bash
    cd /path/to/javafiles
    java -jar filetorun.jar
    (replacing of course the right directories/file names)

    Then save the file, open a shell and cd to the directory you saved the script in. Then,
    Code:
    chmod +x shellscript
    sudo cp shellscript /usr/bin
    and the program can be run like any other (ie. by typing the name of the shellscript in a terminal, in Alt-F2, or in a launcher in the menu).

    To add the program to the menu, use the menu editor in Applications > System Tools.
    www.bsodcomic.com
    "Because life looks better in .jpg"

  3. #3
    Join Date
    Jan 2006
    Beans
    38

    Re: How can i make java program executable?

    Thanks for your quick reply, i really appreciate it. I tried what you instructed me to do, it works if i run it from the terminal but not on double clicking it or by the ALT+F2 (Run Application). If you don't mind asking you this (just an additional info for me) I am wondering why do i have to copy the shell script that i created to the /usr/bin directory?

  4. #4
    Join Date
    Feb 2005
    Location
    Sydney, Australia
    Beans
    375
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: How can i make java program executable?

    Hmm... the program should work from the run application if it's in /usr/bin i think. Executable files in /usr/bin, or in /usr/local/bin, or similar can be run without having to type the full path of the executable in.

    You can also run the file by typing in the full path in either a terminal or the run application and not have to put it in /usr/bin, i just think it simplifies the process (perhaps not). Perhaps try putting the script in the directory where the program is, remove the line in it with 'cd /blah/blah' and run it by entering the entire path to the script (ie. in a terminal or run application '/home/user/program/script'). Maybe i should have started off simpler, so it's easier to tell where things went wrong
    www.bsodcomic.com
    "Because life looks better in .jpg"

  5. #5
    Join Date
    Oct 2005
    Location
    sydney, australia
    Beans
    364
    Distro
    Ubuntu Breezy 5.10

    Re: How can i make java program executable?

    he is putting the executable in /usr/bin to avoid changing the path variable. for self made scripts like this i would make a directory in my home directory called bin

    mkdir $HOME/bin

    then put the script in it and add the following to ~/.bashrc

    PATH=$PATH:$HOME/bin

    but its just a personal preference thing really.
    You dont know the power of the dark space; i must obey my axioms!

  6. #6
    Join Date
    Jan 2006
    Location
    Baltimore
    Beans
    122

    Re: How can i make java program executable?

    Quote Originally Posted by Packard Dell
    I am wondering why do i have to copy the shell script that i created to the /usr/bin directory?
    By default, all the scripts present in /usr/bin can be run directly from any location cos /usr/bin is present in ur $PATH. So if u add any script into that folder, you can run it from anywhere.

    One more thing you would have noticed is that we have to type ./progname to execute any prog in your current directory. (the ./ is for the current directory) Because of some reason they decided to not include the current directory in the path. So the best thing to do would be what darth_vector suggested. Create a folder and add it to the path variable.
    To understand recursion you must understand recursion

    http://krishnamurthy.net.in

  7. #7
    Join Date
    Aug 2005
    Beans
    73

    Re: How can i make java program executable?

    Quote Originally Posted by darth_vector
    he is putting the executable in /usr/bin to avoid changing the path variable. for self made scripts like this i would make a directory in my home directory called bin

    mkdir $HOME/bin

    then put the script in it and add the following to ~/.bashrc

    PATH=$PATH:$HOME/bin

    but its just a personal preference thing really.
    There is no need to modify the path variable, it is already done in .bash_profile for $HOME/bin
    Touting "community" as a strength of a distribution is the equivalent of stating that it has poor documentation.

  8. #8
    Join Date
    Oct 2005
    Location
    sydney, australia
    Beans
    364
    Distro
    Ubuntu Breezy 5.10

    Re: How can i make java program executable?

    it is too! ubuntu is full of nice things like that
    You dont know the power of the dark space; i must obey my axioms!

  9. #9
    Join Date
    Feb 2005
    Location
    Sydney, Australia
    Beans
    375
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: How can i make java program executable?

    Wow.. never knew that, well something new learned today.
    www.bsodcomic.com
    "Because life looks better in .jpg"

  10. #10
    Join Date
    Jan 2006
    Beans
    38

    Re: How can i make java program executable?

    Thanks. I tried all your suggestions but still no luck at all. Nothing is happening when i double click it or run it from ALT+F2, but i can run it from terminal though in any directory. There must be some other way of solving this.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •