Java Program Shortcut

How do I create a shortcut for a Java program?

There are two types of shortcuts that can be created for a Java program (or any program for that matter):

  • a program shortcut or launcher with its own icon
  • a simple batch file or script (best used for unattended usage)

Windows: Creating a program shortcut with its own icon

STEP 1: Suppose we wish to create a program shortcut for GmailAssistant on the desktop. Right-click on an empty spot on the desktop, and select New > Shortcut. Set the location of the shortcut to the executable JAR file ("C:\Path\To\GmailAssistant.jar"). In the next dialog, provide a suitable title for this shortcut ("GmailAssistant").

Creating a program shortcut on the desktop

STEP 2: Next, right-click on the newly created program shortcut and select Properties. Add additional command-line arguments in the Target field if necessary. You can also change the startup directory (specified by the Start in field), or the icon for the shortcut (click on Change Icon).

Set properties for the program shortcut

STEP 3: Finally, you can leave the program shortcut on the desktop, or drag it to a folder of your choice (e.g. the Quick Launch toolbar, or the Start Menu).

Windows: Creating a simple batch (.bat) file

STEP 1: Suppose we wish to create a batch file that runs GmailAssistant. Create a new file with the bat extension ("GmailAssistant.bat"), containing the following single line:

C:\Path\To\java.exe -jar C:\Path\To\GmailAssistant.jar --switches

Ubuntu: Creating a program launcher with its own icon

STEP 1: Suppose we wish to create a program launcher for GmailAssistant on the desktop. Right-click on an empty spot on the desktop, and select Create Launcher. Provide a suitable name for the program ("GmailAssistant"), and set the command for the executable JAR file ("/Path/To/java -jar /Path/To/GmailAssistant.jar"). Add additional command-line arguments in the Command field if necessary. You can also set the icon for the launcher.

Creating a new program launcher on the desktop

STEP 2: Finally, you can leave the program launcher on the desktop, or drag it to a folder of your choice.

Ubuntu: Creating a simple script

STEP 1: Suppose we wish to create a script that runs GmailAssistant. Create a new file with the sh extension ("GmailAssistant.sh"), containing the following two lines:

#!/bin/sh
/Path/To/java -jar /Path/To/GmailAssistant.jar --switches

STEP 2: Run the following command to make the file executable:

chmod u+x GmailAssistant.sh

Other Resources