Compiling and Executing on the GL System

Java on the Linux (GL) Servers

All students must use the Java compiler and JVM found in the directory /usr/local/bin.

To check which compiler and JVM you are using, run the command: which javac

If the result is /usr/local/bin/javac then you're good to go. If the result is /usr/bin/javac then follow the steps below.

  1. Open your .cshrc file (found in your home directory — note the leading dot) with a text editor such as Xemacs or pico.
  2. Add the following lines at the bottom of your file:
    alias javac /usr/local/bin/javac
    alias java /usr/local/bin/java
  3. Save your .cshrc file and exit the editor.
  4. Run the command source .cshrc (again, note the leading dot).
  5. Run the command which javac. The result should be javac: aliased to /usr/local/bin/javac
  6. Run the command which java. The result should be java: aliased to /usr/local/bin/java

If you develop your projects on your own computer, be sure that you are using javac version 1.6.x, also known as Java 6 or JavaSE 6. You can verify the version you are using by running the java -version and javac -version commands.

NOTE, WARNING, ALERT: If the project is text-based, you can compile and execute your program from your PC at home or from any OIT lab. HOWEVER… if the project is GUI-based, you MUST run your program from a Linux machine in an OIT lab in order to test it on GL. You WILL NOT be able to execute a GUI-based project from your PC at home.

Compiling and Executing

It is vital that you compile and execute your code from the GL command line to ensure that it still functions well that way. Our testing for grading is done from the GL command line, not from within Eclipse. There are enough differences between the two that it is important for you to check that your program runs equivalently under both.

If you developed your code other than in a UMBC lab (e.g., on your own computer), you should copy all of your Java code into a test directory in your GL account, as you were taught in lab. If you developed your code directly on the GL machines, you should instead 'cd' into the appropriate project directory in your Eclipse workspace.

The next step is to create a temporary directory to build your compiled files into. In your project directory, you should at least have the directory src. Inside of this src directory should be a subdirectory called projX (your "package" folder), where 'X' is the number of the project you are working on (e.g. proj2 if you are working on Project 2). The projX directory should in turn contain your .java file(s). To verify this, type

ls src/projX

(Your project directory will probably also contain a subdirectory named "bin"--we do not care about this, although Eclipse does, so do not touch this.)

Now, create a new directory called "test" inside of your project directory with the mkdir command, then change into that new directory:

mkdir test
cd test

Now, you are ready to use the javac command to compile the contents of your projX directory. The -d compiler option tells the compiler to place its output (the .class files) into the appropriate directory structure (including subdirectories for each package) under the specified directory, which in this case is '.', meaning your current directory; if you did the above steps correctly, this should be your newly-created test directory.

javac -d . ../src/*/*.java

Verify that your .class files are there, in the appropriate package subdirectory, by typing

ls projX

To execute your code, use the command

java projX.ProjX
In the above, projX.ProjX could be replaced with whatever package name and class name you wish to invoke main() from.