CPSC 559 - Introduction to Distributed Systems
Resources
Running from the Command Line
I have few notes which will hopefully help all of you be running properly off the command line for you demo (and turning code into me which runs properly from my command line). Please note that you are responsibly for documenting in your assignment the command for me to invoke your program (both client and server, which should be different), which ever method you choose. I have tried to make these notes as correct and as useful as possible, but they may infact be wrong or unhelpful. If such is the case please feel free to contact me either with corrections or with questions.
Classpath, Compiling and Running
The Java Glossary has a good (if windows centric) description of the classpath and how to make use of it, particularly how to include jars in your classpath. In short, you will need to let javac and java know where the important .jar files reside. This can be done specifying an environment variable CLASSPATH or by using the argument -classpath (for either program) to include the path to each .jar file (in all versions before Java 1.6, you need to explicitly name each .jar file, it seems in Java 1.6 you should be able to use a wild-card to include all .jar files). Using this you should be able to run your classes from the command line simply invoking java on your main class.
If you are planning to use the -classpath option for javac and java, I would appreciate it if you provided me with a script to run them. Oliver's script will be acceptable for this, but keep in mind that you need to understand what your script does for the demo.
If you are planning to set your CLASSPATH environment variable in bash (which I recommend as a shell) you will probably want to ensure that the CLASSPATH is set each time you log in.
To see what shell you are using you can use the chsh command. If this is not /bin/bash/ you might wish to change it (otherwise you will have to look up setting environment variables for yourself), otherwise retype what the script tells you is your running shell.
In bash there are two scripts which are run depending on how you log into the system, .bash_profile and .bashrc. Generally one of these (in my case .bash_profile) contains a command to read the other file (it should read like ". ~"). In general editing .bash_profile should be sufficient. (I suggest reading the man page for bash to familiarize yourself better with this.)
The CLASSPATH consists of a colon separated list of paths to places where .class files reside. This includes directories on your system with these files and any .jar files you need as well. To set the CLASSPATH you will need to add the two following lines to the file of your choice:
CLASSPATH=$CLASSPATH:"<path to your first .jar>:<path to your second .jar>:"
export CLASSPATH
To test this either log out and in again or start a new instance of bash (by entering bash on the command-line and type echo $CLASSPATH to get the shell to repeat it's current setting for the variable. If this succeeds you should see something along the lines of /home/.../jdom.jar:/home/.../core.jar. If not there may be something odd about how you set the variable or how the instance of bash is executing its profile information (seek professional help).
You can also include the path to the directory containing any other java classes you man need. You might also need to include your current directory (".") in your CLASSPATH.
Executable .jar files
Executable .jar files are .jar files that include a main class entry in their manifests. This allows java to know which class to execute when running the jar. To invoke java you can use the following command: java -jar client.jar. The Java Glossary also includes a good entry on .jar files and on how to execute them. Note if you are using executable .jar files you will probably need to include classpath directions to any .jar files your code needs to access.
Page Updated: July 2, 2008 at 1530 MST