0

New to Linux but very happy with it so far and been able to learn a lot.

Currently opening a folder that contains Example.jar, then opening terminal, next entering java -jar Example.jar to launch the jar file.

Ideally would like to double click a icon on the desktop to do the aforementioned.

Is this possible?

Running Linux Mint but believe the steps would be the same.

0

1 Answer 1

2

You'll need to create a .desktop file. To do this, create a new file named something like ExampleLauncher.desktop (the name isn't too important, since window managers will likely read the name from inside the file and display that inside). Then, open that file in your favorite editor (double-clicking may not work in this case, so you'll need to drag the file in), and add the following:

[Desktop Entry]
Version=1.0
Name=JOSM Imports
GenericName=Java OpenStreetMap Editor
Comment=Editor for OpenStreetMap.org
Exec=JAVA_OPTS="-Djosm.home=/home/saikrishna/.josm-imports/" josm
Icon=josm.png
Terminal=false
Type=Application
Categories=Education;Geography;

This is what I have to run a custom instance of JOSM. Obviously, the content you'll have will be different.

Here is an explanation of each line:

  • Version=1.0: Specifies the specification version of the .desktop file. Keep this unchanged.

  • Name=: Name that will be displayed in the menu (if you put this in ~/.local/share/applications or /usr/share/applications)

  • GenericName=: Generic name of the program. This is like the category that a program falls under.

  • Comment=: This may be used in displaying the tooltip.

  • Exec=: This is what will be run when this file is activated. Unless what you are running is in your $PATH, I recommend you use an absolute path.

  • Icon=: This is an icon file name that will be displayed. If there's no specific icon, you can skip this.

  • Terminal=: Specify if a terminal window should open when this is activated. For GUI programs, this will typically be false.

  • Type=Application: This is the type of .desktop file. There are other types, but leave this as-is.

  • Categories=: This is the category that the program will fall under. This is mainly used in window managers that have hierarchical menus.

For a full list of valid keys and their descriptions, see here.

3
  • Thanks for the answer. So for the Exec section would I put my 'code' java -jar Example.jar 'code' before the path?
    – Kenny
    May 27, 2015 at 11:26
  • In your case, you should have Exec=java -jar /path/to/Example.jar. May 27, 2015 at 15:16
  • Place it in /usr/share/applications to show it in the Applications menu.
    – Caio Mar
    Nov 19, 2021 at 18:30

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