Visit the Help Desk
Knowledgebase
Define Java Classpath on CPSC Linux Workstations
Posted by Leo Leung on 03 October 2013 10:20 AM

Follow the following steps to modify the class path of your shell's environment.

1. Determine which shell you are using

Run on the terminal:

$ finger $USER

You may substitute $USER with your own CPSC username. The command will show information about your account, including the shell that you are using. You will see something similar to:

Shell: /bin/bash 

The value there is the shell you are using.

2A. For Bash shells

Create or edit .bashrc file on your home directory to contain:

CLASSPATH=.:/usr/share/java/:
export CLASSPATH

(Hint: Run 'vi ~/.bashrc')

You may define custom paths by appending to the CLASSPATH variable, separated by colons (:).

2B. For tcsh/csh shells

Create or edit .cshrc file on your home directory to contain:

setenv CLASSPATH .:/usr/share/java/:

(Hint: Run 'vi ~/.cshrc)

You may define custom paths by appending to the CLASSPATH variable, separated by colons (:).

3. CPSC 331 Specific Requirements

If you are in CPSC 331 (Fall 2013), you are to use a subdirectory in your home directory as part of your class path. To determine the full path name of your class path, go to the directory containing your java classes and run the 'pwd' command.

For instance, if you are placing all your compiled java classes in a 'java' directory in your home directory:

~$ cd java
~$ pwd
/home/uga/username/java

3.1A. For Bash Shell

Prepend the full path from 'pwd' from above (/home/uga/username/java) to the CLASSPATH and create a javac alias to define your java class directory using the alias command in your .bashrc file.

Extending the example above, your .bashrc file should look something similar to:

CLASSPATH=/home/uga/username/java:.:/usr/share/java:
export CLASSPATH 
alias javac="javac -d /home/uga/username/java" 

3.2A. For tcsh/csh Shell

Prepend the full path from 'pwd' from above (/home/uga/username/java) to the CLASSPATH and create a javac alias to define your java class directory using the alias command in your .cshrc file.

Extending the example above, your .cshrc file should look something similar to:

setenv CLASSPATH /home/uga/username/java:.:/usr/share/java:
alias javac javac -d /home/uga/username/java

4. Reload your shell

Reload your shell by running:

exec $SHELL

You can verify whether your class path was set properly by running:

env | grep -i classpath

You should see something similar to:

$ env|grep -i classpath
CLASSPATH=.:/usr/share/java/junit4.jar:/usr/share/java:


If you are still having issues, please drop by the help desk at MS-151.
(0 vote(s))
This article was helpful
This article was not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
Help Desk Software by Kayako Fusion