Running Java Applications

Some java software may be run as a stand-alone application outside of a web browser. This requires the JavaTM 2 SDK Tools which come with the JavaTM 2 Runtime Environment (JRE) software. In particular, you'll need
java - the Java application launcher
which should be located in the "bin" directory of your JRE installation. Go to http://java.sun.com and read their documentation on "the Java application launcher". Be aware that only java programs with a "main" method can be run as applications (you'll get a "NoSuchMethodError" referring to "main" if the program lacks a main method).

A Brief How-To

This page will briefly explain how to launch a java application on a Windows system. It is assumed that the java application is a jar archive file residing in a local directory on your system whose name ends with .jar. If you can find a command prompt and navigate to the directory containing the jar file named "SomeJavaApp.jar", you can type
java -jar SomeJavaApp.jar

to launch the app. Otherwise read on.

The Easy Way

Windows may already know it should open jar files with the application launcher. If so, you can double-click the jar archive file to launch it as you would any other program. Otherwise, double-clicking the jar file should bring up an "Open With" window with a checkbox that says "Always use this program to open this file" - all you need to do is locate the "java.exe" file (the launcher) and select it (select the "javaw.exe" file to run java with no console window). If you don't see the launcher listed in the "Open With" window, you can use the "Other..." button to browse around and find it. The surest place to look is in the "bin" directory of your JRE installation, although there might also be a copy of the file in the Windows directory. Usually the path to the launcher resembles
C:\Program Files\Java\j2re1.4.2_03\bin\javaw.exe
or maybe
C:\Program Files\JavaSoft\JRE\1.3.1_06\bin\javaw.exe.
If the "Open With" window approach didn't work out, launch Windows Explorer and use the menu item "Folder Options->File Types" to associate jar files (with extension .jar) with the launcher program.

Command Line Intro

This section refers to the use of the command line to type in commands. If this is unfamailiar to you, look up "command prompt" in Windows help and read this introduction. To run a program, you type the name of the program on the command line and hit Enter. For example, you could type in "java.exe" to run the application launcher. Some programs accept an additional file name on the command line. For example, the app launcher can be run with

java.exe SomeJavaClass

to launch a java program named SomeJavaClass. In fact, you can drop the ".exe" from the command :
java SomeJavaClass

will work the same. Where do you enter commands? Under the Start button there is a "Run" item which brings up a window which allows you to enter commands. A better place to enter commands is at a command prompt. Check Windows Help to locate and launch the command prompt window. The command prompt window is often called a console window. It displays the current drive and directory and you can type in commands such as "dir" to list the directory's contents. Other commands allow you to change directories and navigate around your system. Read the help entries on the MS-DOS commands to learn more.

Running the Application Launcher from the Command Line

If you enter "java" on the command line, you can get a help message describing the usage of the java application launcher. Try entering the following on the command line :

java -version

You should see a message concerning the JRE version unless the system can't find the launcher (java.exe). If you get a "Bad command or file name" message, you'll need to add the location of the launcher to your system's PATH, a topic which is beyond the scope of this explanation. If you know where the launcher is, you can put the full path on the command line (enclose commands in quotes if there are blank spaces):
"C:\Program Files\Java\j2re1.4.2_03\bin\java" -version

Note : Replace the typical path above with your actual path to the launcher.
Hint : the Windows directory is always in the PATH, so if you place a copy of the launcher file there, you can omit the path and just type in "java".

Assuming you can successfully run the app launcher from the command line, locate the .jar archive file. You will need to type in its full path on the command line. Say the jar file is named "SomeJavaApp.jar" and it is located in the directory "C:\javastuff\". You would launch it by entering the following command :

java -jar -cp C:\javastuff C:\javastuff\SomeJavaApp.jar

The "-jar" and "-cp" items tell the app launcher that the java program is a jar file and that the paths to it are included in the command. As mentioned above, you might need to include the entire path to the app launcher:
"C:\Program Files\Java\j2re1.4.2_03\bin\java" -jar -cp C:\javastuff C:\javastuff\SomeJavaApp.jar

Using a Command Prompt console window to enter your commands allows you to see any error messages as well as other messages generated by the java program.

Why Would Anyone Type All This on a Command Line ?

Instead of using the "-cp" option, which requires putting the path on the command line, you can navigate to the directory containing the jar archive file and then type

java -jar SomeJavaApp.jar

to launch the SomeJavaApp.jar file as an application. To navigate, use the "cd" or "chdir" (stands for change directory) DOS command.

Here is an example which uses the "cd" command to change directories :
Launch the command prompt window, then type

cd \

and hit enter. The backslash after "cd" changes directories to the root directory. From there you can change directories to the one with the jar file by typing something like
cd javastuff

or
cd javastuff\somedirectory\somesubdirectory

and then view the contents of the directory by typing
dir /p

If you see the jar file listed, you can type
java -jar SomeJavaApp.jar

to launch SomeJavaApp.jar.

One Last Bit

The DOS "exit" command will close the command prompt window.