CS310
Java Development Setup: on
UNIX and on your home PC, Spring 2009
UNIX
Java setup.
Add
modules java6
to
your .cshrc on UNIX. Note
that it
is important to edit .cshrc before
the line "if (! $?prompt) exit", so that the edits are in effect even
for the subshells that do the exit. Just add these new
modules to
the "module load standard" line, so it reads "module load standard
java6". To activate your new .cshrc settings, use "source
.cshrc", or log out and in again.
UNIX
editor: Hopefully you know
emacs or another editor on UNIX. We will do most of our
software development on PCs, and then test the systems on UNIX as well
as PC. This works well because of the robust portability of
Java. Project deliveries are on UNIX.
UNIX
java setup test:
(Use "source .cshrc" first if you just
changed .cshrc.)
java
-version should output
java
version "1.6.0_04", plus two more
lines of text.
The JAVA_HOME environment
variable is needed by some ant tasks and other tools. To
check it:
env|grep
JAVA should output
JAVA_HOME=/tools/jdk-1.6.0_04/usr/jdk/jdk1.6.0_04
env|grep CLASSPATH should output nothing.
If it does give output, try to hunt down the source.
If it
has junit.jar, that's OK.
If it does have other needed jars, it should also have "."
to include the current
directory, with a colon separating it from the other jar(s), for
example, CLASSPATH=/tools/junit-3.8.1/junit.jar:.
Home PC/Mac Setup
Java
– We will be using Java 6 from Sun. Everything we
need from
Sun is in the Java SE (Java Standard Edition) download, that is,
the JDK (Java Development Kit) for Java 6. Note
that the
JRE (Java runtime environment) is not enough. Download and install
the latest (Update 11 as of Jan., '09) JDK from http://java.sun.com/javase/downloads/index.jsp.
It takes about 160MB of disk space.
Note
that the Java SE installation will install a system JRE, i.e., possibly
disrupt other Java development on the system if you need an older Java
(Java 1.4 say) for some reason, but fine if this system is
used
only for current Java development. Java 6 can be used as a maintenance
release of Java 5 for normal Java programming.
- You do not
need to download NetBeans. NetBeans
is an IDE that we
will not be using.
- You
do not
need to download the JRE
(Java Runtime Environment) It
is included
in the JSE and JEE SDK
downloads.
- Note:
Sun does not support Mac OS. Go to Mac OSX JDK versions.You
probably have some version of java already. Go to the UNIX prompt in
Terminal and do "javac -version" as described above for UNIX at
cs.umb.edu. If it shows 1.6xx, for anything after the 6, you can skip
the JDK download. Even 1.5xx will do. But 1.4xx is too old.
JAVA_HOME
and
Path: Use
System Control
Panel>Advanced>Environment to define the JAVA_HOME user
environment variable as c:\Program Files\Sun\jdk1.6.0_0x or
c:\Sun\jdk1.6.0_0x or whereever you put the JDK download. To
enable
command-line java
development, edit
your user Path environment
variable to include your JDK's bin
directory, using %JAVA_HOME%\bin as its value. Use a semicolon between
entries in the value of Path. For
example, my Path value has c:\Program Files\emacs\bin;
%JAVA_HOME%\bin;
Windows
java setup
test (use
a brand new command window if you just changed your
environment
variables)
java
-version
should
output
java version "1.6.0_0x" where x is some update number
Java(TM) SE Runtime Environment (build
1.6.0_0x-xxx)
Java HotSpot(TM) Client VM (build
1.6.0_0x-xxx, mixed mode, sharing)
javac -version
should output
javac 1.6.0_0x
set|find
"JAVA"
should output
JAVA_HOME=c:\Sun\SDK\jdk
or whatever
you specified as the JDK directory
dir %JAVA_HOME%
should show directories bin, demo, include, jre, lib, and sample, as
well as some files.
set|find
"CLASSPATH"
should
output nothing. If it does give output, look for an old
environment variable setting and delete it. (junit.jar is OK to have in
CLASSPATH, along with ";." to include the current directory as well.)
path
outputs the operational Path value,
which is the system Path value appended with the user Path value you
set up in the control panel, so near the end of the displayed path, you
should see c:\Program
Files\Sun\jdk1.6.0_03\bin or
c:\Sun\SDK\jdk\bin.
Failure case: All
set up as above, but java -version shows
java
1.5.x (or some other wrong version. Look for a java.exe in Window's
system32 directory. Just
rename it to
java_hold.exe.
It's best to have Java working first, then install eclipse, so that
eclipse can find the new JDK on its own. But if you install
eclipse before Java, you can configure the new JDK in eclipse as shown
in step 2. below.
You may use the IDE of your choice, but it's best to stick to ones
known by many people locally, that is, emacs, Dr Java, or eclipse.
I use emacs on UNIX and eclipse on my PC and also on my Mac
laptop. Eclipse takes a little time to learn, but it saves time in the
long run by giving you easy ways to rename variables, classes, etc.,
find all uses of variable, method, etc., display an inheritance
hierarchy, generate getters and setters, extract interfaces, do global
edits, do visual compares, and so on.
Eclipse "Ganymede": Eclipse for
Java IDE
- Install
the "Eclipse IDE for Java Developers" from www.eclipse.org.
This
also free.
Put it in c:\eclipse-whatever.
- Make sure eclipse sees your
Java 6.0 JDK by visiting
Window>Preferences>Java>Installed JREs, and
looking for the
Java 6 JDK. If it's not there, click
the Add button, and fill in:
JRE name: jdk6
JRE home directory: c:\Program
Files\Sun\jdk1.6.0_0x or ...
and clicking OK. Then make sure it is checkedcd
as the default
JRE in the "Installed JREs" window you should return to.
Eclipse Notes tricks
worth knowing:
1. To reinitialize a project, delete it, keeping files, in eclipse. Then go
to the top-level project directory in the file system and remove all
the dot files (.project, .classpath, and .settings, a directory). Then
start up a new project, selecting the non-default location for the
project.
2. Similarly, if you need to build a project from given files, delete any dot files first.
3. If a project seems to be ignoring an edit or other showing other
weirdness, use Project>Clean to clean out all the derivitive files,
i.e., force a full rebuild. If this doesn't work, use trick 1.
Emacs is installed on all our UNIX systems, and comes with Mac OSX.
Installing Emacs on PC: See
http://cs11x.cs.umb.edu/mediawiki/index.php/Emacs
Simply use cs310 instead of cs110.
Transferring Files to our UNIX
site: you need to use secure file transfer, SSH/SFTP. ssh and scp are
installed on all our UNIX systems, and come with Mac OSX. For
See
http://cs11x.cs.umb.edu/mediawiki/index.php/SSH_and_SFTP