How to run and Java programs1. Making sure prerequisites are installedYour machine or the host you are logged in to must have these tools correctly installed:
2. Setting up your environmentSome of the scripts in this course depend on certain environment variables being set.JAVADIRThis variable must point to the location of the directory containing your desired installation of the Java SDK.
JOOSDIRThis variable tells scripts where to find the JOOS binaries and libraries. Example:setenv JOOSDIR $HOME/cs520/public_html/joos
if you are using
export JOOSDIR=$HOME/cs520/public_html/joos
if you are using CLASSPATHThis variable tellsjavac and java
where to find required libraries. We would like to add the
current directory . to our CLASSPATH as well the
jar file containing the JOOS libraries,
jooslib.jar :
setenv CLASSPATH .:$JOOSDIR/jooslib.jar:$CLASSPATHor
export CLASSPATH=.:$JOOSDIR/jooslib.jar:$CLASSPATH
for PATHNow you can add the JAVADIR and JOOSDIR binaries to your path using:
setenv PATH $JAVADIR/bin:$JOOSDIR/bin:$PATHor
export PATH=$JAVADIR/bin:$JOOSDIR/bin:$PATH
for Note: as you will be modifying the A- JOOS compiler, you may find it convenient to place the directory containing your modifications on your path as well. 3. Using the various toolsThis section describes the use of the various tools needed for the JOOS project. It assumes that the environment variables in the previous section have been set properly.joosa+This is the A+ JOOS compiler. It is actually a wrapper script around binaries for several different architectures that looks at the value of$HOSTTYPE to determine
what to execute.
Task: compile JOOS programs using the A+ compiler into a similar collection of Jasmin files:
$ joosa+ f1.java f2.java ... fn.java f1.joos f2.joos ... fn.joos
Note that JOOS programs are really collections of regular
joosThis is the A- JOOS compiler. It converts Java source code.java files to Jasmin assembler .j
files that contain human-readable representations of Java
bytecode.
The A- source code is in
joosa-This is a wrapper around the A- JOOS compiler. It expects to find a binary calledjoos on your PATH, and for the
JOOSDIR environment variable to be set.
Task: Compile a JOOS program using the
joosa- script:
$ joos f1.java f2.java ... fn.java f1.joos f2.joos ... fn.joosNote that here the .joos extern files are ones that
you have written; the script already pulls in all of the externs
from the $JOOSDIR/extern directory.
jasminThis is the Jasmin assembler. It is actually a wrapper script that callsjava to execute jasmin.Main .
Task: convert the Jasmin
$ jasmin f1.j f2.j ... fn.j jooscThis is a convenience wrapper script that callsjoosa- and then calls jasmin for a JOOS
program.
Task: compile a JOOS program directly to Java bytecode:
$ joosc f1.java f2.java ... fn.java f1.joos f2.joos ... fn.joosNote that this will also leave the intermediate .j
files in the current directory.
javacThis is the official Java compiler. You can confirm that it is version 1.5 by typingjava -version .
Task: compile JOOS programs, which are also Java programs, into a similar collection of class files using the official JDK:
$ javac f1.java f2.java ... fn.java
If your CLASSPATH is set properly this will work, because
dejavaThis is the D-Java.class file disassembler. It is
actually a wrapper script around binaries for several different
architectures that looks at the value of $HOSTTYPE
to determine what to execute.
Task: disassemble a collection of Java
$ dejava f1.class f2.class ... fn.class
java -verifyThis is the Java virtual machine running with the class file verifier turned on. The verifier makes sure that the bytecode obeys the rules of the Java Virtual Machine Specification.
Task: execute and verify
$ java -verify Main
where Main is the main class of the application. Note that you
must not use an extension here. If your CLASSPATH is set
properly this will work, because 4. Understanding the tool relationships
|
Maintained by Laurie Hendren [HOME] |