Quick Guide

on Running Java Programs

Content

This page contains some basic pointers on how to run Java programs, like ensuring the right version of Java is available (the K.U.Leuven JCHR system requires Java 1.5 or higher!) and setting the class search path.

Of course this will mainly be focused on running the K.U.Leuven JCHR system. Furthermore the main focus will be the use of Sun's distribution of Java (JRE or SDK) without an IDE. If you are using an alternative implementation or some type of Java IDE (like Eclipse) then you should look at their respective documentations for information.

Java 1.5

The K.U.Leuven JCHR system is written in Java 1.5, so a Java Runtime Environment (JRE) version 1.5 or higher is required to run applications using the system. You can typically check the current version installed on your system by typing:

java -version

The Sun distribution of the JRE can be downloaded here.

Since most of the time you will also need to compile Java-files when using the K.U.Leuven JCHR system (e.g. to compile the generated handler files) you should not only install the JRE, but also the JDK (J2SE Development Kit) available for download at the same location. This includes the basic tools required to create Java applications, including a Java 1.5 compiler. Checking which version (if any) is installed on your system can typically be done by typing:

javac -version

Note that when installing the JDK the installation program in general will ask whether you want to install the JRE as well.

Set the Java class search path

When the Java VM runs your program it searches for application .class files using the paths listed in the class search path. Likewise the compiler will search for required components. By default these Java programs looks for classes in the current working directory. However, if your program uses classes that are not in the current working directory, then you need to explicitly list all the directories containing classes used by this application. In addition, if your program uses classes contained in a JAR (Java ARchive) file, then the JAR file must be listed in the class search path as well.

There are two ways to specify the class search path:

  1. Using the classpath-option of the Java program, e.g.
    java -classpath ***** SomeClassContainingMain
    or like ways:
     javac -classpath ***** SomeSourceFile.java
  2. Using a CLASSPATH environment variable. For a Windows system:
    set CLASSPATH=*****
    For a Linux system:
    export CLASSPATH *****
    or, depending on the type of shell you are using:
    setenv CLASSPATH *****

Most systems offer ways of setting environment variables other then from the command line; e.g. in Windows XP this can be done in Control Panel -> System -> Advanced -> Environment Variables. The advantage of the latter method is that these settings are persistent (i.e. you do not have to set the class path each time you want to use the system again).

In any case the ***** has to be replaced by a list of (absolute or relative) paths to directories and/or JAR files. On a Windows system this list is separated by semicolons, e.g.

.;c:\java\libraries\;..\KUL_JCHR.jar 

On a Linux system the list is separated by colons:

.:/home/java/libraries/:../KUL_JCHR.jar

Note that in both cases we included the current directory by typing a '.' in the list. Since in general using the K.U.Leuven JCHR system requires several libraries (i.e. JAR files), using the second option (i.e. the environment variable) is probably preferable. We will always denote the libraries required, but is generally easier to include all JAR's directly in your CLASSPATH environment variable even if not strictly needed.