Compiling and Executing Java Code on the GL System

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

As discussed in the previous step of this lab, if you developed your code elsewhere (e.g., your own computer) you should have now copied all of your Java code into a test directory in your GL account, say "~/Lab3"; cd into that directory now. If you were developing your code directly on the GL machines, you should instead 'cd' into the appropriate project directory in your Eclipse workspace there (most likely "~/workspace/Lab3").

The next step is to create a temporary directory to build your compiled files into. In your Lab3 directory, you should at least have the directory src. Inside of this src directory should be a subdirectory called lab3 (your "package" folder), which in turn contains your .java file(s). To verify this, type

ls src/lab3

(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 "Lab3" with 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 the lab3 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 subdirectories, by typing

ls -r

To execute your code, use the command

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