How to create a Desktop Icon on Ubuntu

Hi

In the age of AI, sharing information might no longer seem “necessary”—after all, AI is supposedly all-powerful, all-knowing, and omnipresent. Nevertheless, as a seasoned “old geezer,” I am sharing this post for those who still enjoy tinkering with software and operating systems. Today, I will show you how to create a desktop icon in Ubuntu 26.04.1 LTS that executes a Java JAR file. In this example, I am using a JAR file named “netxfer.jar,” which requires three parameters: two strings (as localID and remoteID) and an integer an index used to select a port from a ComboBox).

java -jar netxfer erika joe 1

The code was built using OpenJDK 27 in conjunction with OpenJavaFX. Therefore, I need to define an environment variable as follows:

export JDK_JAVA_OPTIONS=-Duser.language=en -Duser.country=US --module-path "/home/joe/javafx/lib" --add-modules javafx.controls,javafx.fxml,javafx.swing --enable-native-access=javafx.graphics


Fig. 1

Figure 1 shows what the app looks like. With this application, I can transfer directories or files between computers—using IPv6 (at a speed of approximately 15 MB/second).

  1. If your Ubuntu system is set to English, you will find a folder named “Desktop.” Otherwise, you will need to look for the folder that corresponds to the translation of “Desktop” in your language (for example, in German, it is called “Schreibtisch”). This folder contains all the definitions for applications that are to be displayed on the desktop (see Figure 2).


Fig. 2
2) Edit the relevant file—in my case, “XFileTransfer.desktop”—and save it in the Desktop folder (see Figure 2).
3) Shortly thereafter, a “blurred” icon will appear on the desktop. Right-click on it and select “Allow Launching.” The icon will then become clear and sharp (see Picture 3).


Fig. 3

Double-clicking the icon (in this case, a globe with a red arrow) launches the application (Fig. 1). However, if you would also like the application—along with its icon—to appear in the Ubuntu application menu (shown in the bottom-left of Figure 2), you must copy the .desktop file you created into the /usr/share/applications directory and follow these steps:

sudo cp $HOME/Desktop/XFileTransfer.desktop /usr/share/applications
cd /usr/share/applications
sudo chmod +x XFileTransfer.desktop

I prefer copying the file rather than using a symbolic link. Once this is done, open the Ubuntu application menu; your application should now appear there (see Figure 4). If you would also like the application to appear in the left-hand bar (the dock), simply right-click the icon and select “Pin to Dock.” Your app is now ready to be launched with a single click.


Fig. 4

Per Linux standard:

  • If the *.desktop file is installed manually, it should go to “/usr/local/share/applications”, not “/usr/share/applications”. The without-local path is for files installed by OS package managers (apt, dnf).
  • Looking at your desktop file, the Exec and Icon are pointing to some files in user $HOME folder. Then the desktop file should be installed to “~/.local/share/applications” (scoped to a user).
2 Likes

You’re speaking in terms of “Linux in general” – I am referring specifically to Ubuntu 26.04.01 LTS: There is no subfolder named “applications” under “/usr/local/share/applications”; instead, that “applications” folder is located under /usr/share/applications. Take note of it or ignore it—as you wish.

In Ubuntu, the “Desktop” folder exists as ~/Desktop and can be used directly. The reference to ~/.local/share/applications applies only to the specific local user, not to any other users.
You can always “install Ubuntu” and verify for yourself, if you’re an “unbeliever” :rofl:

User will need to manually create it, because “/usr/local” is designated for user to manually install files (not installed by OS package manager).

In Ubuntu, the “Desktop” folder exists as ~/Desktop and can be used directly.

It will only let you see the icon on the “desktop” screen.
By installing desktop files to “~/.local/share/applications”, other tools which need to build menu of installed sofwares, like “application launcher”, can find your app.

You can always “install Ubuntu” and verify for yourself, if you’re an “unbeliever” :rofl:

Don’t laugh on other people when you are just new to Linux world, with just limited knowledge about it. I have been used Linux (mainly Ubuntu) as a daily, sole OS for more than 10 years and published applications myself: https://quan.hoabinh.vn/category/linux/ .

:rofl:I am addressing those who are new to Ubuntu—not the freaks who have been struggling with Linux for years. How, pray tell, is a newbie supposed to know that he needs to “create something manually” when there is a desktop available and is easy to use?

10 years? :rofl: I was already working with AT&T Unix System V and BSD 4.3—probably before you were even born. Don’t be so emotional and sensitive when you have no idea who you’re dealing with. Okay?

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?