Launch a Java Application from an Icon in Windows

Java applications are not native applications in Windows. What do I mean? Well a native application has an EXE extension and if you double-click on it, it will run. Java works differently. When you compile your java program it is not compiled into an EXE, it is compiled into a class. Then you “feed” this class file to the Java interpreter which is a Windows native application. This is done by typing “java.exe MyApp” at the command prompt. Well we don’t use Windows because we love the command prompt, we like icons and shortcuts.

You could make a batch file which contains the command I mentioned before. The problem with that is it will launch a command prompt window for second. That seems kind of hokey to me. My Windows native applications don’t do that. Ok, here is the trick. If you look in your Java bin directory you will see java.exe, well next to it is javaw.exe. This is the guy we want to use, and instead of using a batch file we are going to use a shortcut. Make sure your Java bin directory is set in the Environmental Variable called Path. That way you can simply call the application by name anywhere in the file system.

For this example I have an application called “HelloWorld” and it lives in “C:\Program Files\Java\Hello World”. For your application change the paths and names as needed.

1. Right-click in the folder where your class file lives. Choose New, then Shortcut.


2. Type in “javaw.exe HelloWorld”. Click Next.


3. Now type “Hello World” or what ever you are going to name this shortcut. Click Finish.


4. Now we see the new “Hello World” shortcut. We are not done yet, we need to modify a property.


5. Highlight the Address, right-click, and choose Copy.


6. Now right-click on our new shortcut and choose Properties.


7. Now erase whatever is in the “Start in” box and paste the Address in here. The start in box must contain the folder where the class file lives. Click OK.


8. That’s it. Now double-click the shortcut and your application should launch just like any other application.


You can copy this shortcut anywhere. Your Desktop, Start Menu or Quick Launch and you will have an icon for your Java application. I suggest copying the shortcut, not to move it. That way you will always have it with your application to reuse.