1

I have seen some java applications which I don't type the command in the shell to run it, but when i click a file, it runs the java application. I have only tried

javac myjava.java
java myjava

Typing this entire command on the shell. Can I make it run when a file is clicked? I am new to Linux. Thanks in advance.

1 Answer 1

3

When you run javac myProg.java it creates *.class file. That's the actual executable that runs. The bellow solution allows opening a terminal window and running *.class file.

  1. Create a new desktop file

    gedit ~/.local/share/applications/runJava.desktop
    

    with the following contents:

    [Desktop Entry]
    Encoding=UTF-8
    Version=1.0
    Type=Application
    Name=runJava
    Terminal=true
    Exec=bash -c "FILE=%U;cd $(dirname $FILE );java $(basename $FILE .class);$SHELL"
    

    Save the file.

  2. Right click on any *.class file, select Properties menu, and change default application to runJava

    enter image description here

  3. When done selecting, close the Properties menu, double click the file. *Remember: only .class files that have main method will run

You must log in to answer this question.

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