Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Java Tip 58: Fast launcher for Java apps

Use a simple double-click of the mouse to launch Java apps from the Windows desktop

A previous Java Tip, "Tip 45: Launch Java applications quickly from Windows 95," demonstrated the creation of DOS shortcuts for Java applications. But why not use simple double-clicks of the mouse to launch Java apps from the Windows desktop? This article shows you how to use a small C application to run Java applications as easily as you run your native apps.

Java interpreters don't accept DOS paths as parameters, so you can't use the standard Windows double-click mechanism. To obtain the name of the Java class, the DOS path of a class file must be split, the directory added to the CLASSPATH, and the ".class" extension eliminated from the file's name.

I wrote this article with Windows users in mind -- particularly those who hate to type long commands in a DOS console. To install my C application, just follow the steps described in the proceeding paragraphs. I know you prefer Java to C, so I did the hard work for you; I wrote the app. All you have to do is use it!

Installing JavaLauncher

I don't like Windows programming, so I created a simple console application that you must install manually. Here are the steps:

  • Unzip JavaLauncher.zip (see Resources) in a folder. You might call it "C:\JL", for example.

  • Double-click on a class file (let's call it your_app.class) from Windows Explorer. This may be any of your class files, but it's preferable that it be an application that doesn't need parameters. (In other words, it has a main() method that doesn't use args[].)

  • Windows will ask you what application should be used to "open" the class file, as shown in Figure 1 below.


Figure 1

  • If everything is okay, go on to the next step. If there's a problem, it's probably because you tried, in a previous programming effort, to set another "viewer" for class files. If this is so, you must select the Options item of the View menu in the Windows Explorer GUI. Click on the File Types tab and select the item associated with the class files (see Figure 2). You must edit the properties of this item as shown in the "Using drag-and-drop and menu shortcuts" section below.

    Figure 2

  • Type a description like "Java Class File" in the text field of the window, then press the Other button. Another window is shown, as depicted in Figure 3.

  • You must select JavaLauncher.exe from the directory in which you've just exploded JavaLauncher.zip. Press the Open button of the window shown in Figure 3.

    Figure 3

  • You will return to the window shown in Figure 1. Press the OK button (which should be enabled now). JavaLauncher will try to execute your_app.class using java.exe, so don't choose format_my_hard_disk.class. On my computer, your_class was the HelloUniverse.class that comes with Java 3D (see Figure 4). This was the first application, which I launched with a double-click of the mouse.


Figure 4

Note: Next time you want to launch a Java app, you need only double-click on the class file.

The directory of java.exe must be in the PATH environment variable. Also the CLASSPATH must be set. See the "Using drag-and-drop and menu shortcuts" section below to see the configuration in which I tested JavaLauncher.

1 | 2 | 3 |  Next >
Resources
  • Launch Java applications quickly from Windows 95 http://www.javaworld.com/javatips/jw-javatip45.html
  • You can download the source code and exe files for the JavaLauncher here http://www.javaworld.com/javatips/javatip58/JavaLauncher.zip