Launching Java programs using a Windows desktop icon
Author: Davis Swan
Date: July 30, 2004
The first thing you have to do is create a DOS batch file that will invoke the Java runtime environment, including setting the appropriate CLASSPATH. For example, assume that the Java program that you want to launch is in the jar file
myApp.jar. The batch file could look as follows;
start /B javaw.exe -jar myApp.jar
Note the use of the start command which will create a separate window to run the Java application. The /B switch is supposed to suppress the creation of a new window. In fact, the window does appear momentarily and then disappears. The javaw executable must be used rather than java in order for the launching window to disappear.
Saving this file with a .bat extension will allow it to be launched by double clicking on it. Unfortunately, there is no way to change the icon for a bat file. Therefore, you must create a shortcut that points to the bat file and uses the icon that you want for your application. The shortcut can be set up in the same shared drive that the jar file exists in so that individual users do not need to set it up. Alternatively, users can add it to their own desktop, taskbar, or Start Menu.
Note: There are numerous programs that can be used to create icons. One that I like is Randy's icon editor. This is a Windows exe so it does not have to be "installed", and produces 32x32 16 colour icons. You can also import bmp files, which really helps when trying to work with text. Right-click on the image displayed below to download an ico file created using Randy's icon editor.