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

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