UNIX/Linux
Java
setup for cs.umb.edu systems
We have both Solaris UNIX ("SunOS") and Linux systems in our
departmental
network, as well as Windows PCs. You can access the same login
directory and
other directories from both SunOS and Linux. Use the uname
command to tell which flavor of UNIX is running on a
particular system if you
don't know already: uname will
output
"SunOS" or "Linux". Note that with the standard student
setup, you can tell Linux systems by the $ prompt, vs. SunOs
systems by the % prompt.
Define $cs639: For Linux, add a line to your .profile
file:
cs639=/data/htdocs/cs639;export
cs639
and log out and in again ( or use the command ". .profile")
and try "cd $cs639" and "pwd" to make sure you are cd'd
to /courses/cs639/public_html, the
directory for our
class web page.
For Linux systems, you should not need to do any setup to use
java and ant. To
make sure the java and ant are recent-enough versions,
simply use the commands under UNIX/Linux java and setup tests
below.
SunOS Setup (optional if you want to
stick to Linux (i.e.,
sf08.cs.umb.edu)). For SunOS systems, add
modules java6 and
ant/1.7.0 to your .cshrc. 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 ant/1.7.0". Add
a line
"setenv cs639 /data/htdocs/cs639"
to your .cshrc file to define
$cs639. To activate
your new .cshrc settings, use
"source .cshrc", or log out and in
again. Try "cd $cs639" and "pwd"
to make sure you are cd'd to
/courses/cs639/public_html, the
directory for our class web page.
UNIX/Linux editor: Hopefully you know emacs or
another editor. We will do most of our software
development on PCs, and
then test the systems on UNIX/Linux as well as PC. This
works well because
of the robust portability of Java. Project deliveries
are on UNIX/Linux.
UNIX/Linux java setup
test: (Use
"source .cshrc" first if you just
changed
UNIX .cshrc)
java
-version
should output
java
version "1.6.0_xx", plus two more lines of text,
where xx stands for 2 digits
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_03/usr/jdk/jdk1.6.0_03
(on SunOS)
(JAVA_HOME=/usr on Linux)
env|grep
CLASSPATH
should output
nothing. If it does give output, try to hunt down the
source, usually in
.cshrc for UNIX (.profile on
Linux) or files it
invokes.
UNIX/Linux
ant
setup test:
ant
-version
should output
Apache
Ant version 1.7.0 ...
env|grep ANT should output
ANT_HOME=/tools/apache-ant-1.7.0,
plus possibly other
(unimportant) ANT_ environment variables
Java – We will be using Java 7 (or 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 or 7. Note that the JRE (Java runtime environment) is not enough. Download and install the latest 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 for some reason, but fine if this system is used only for current Java development. Java 7 can be used as a maintenance release of Java 6 or Java 5 for normal Java programming.
If you already have the Java 6 JDK downloaded from Sun within the last year, that's good enough. Also, it's OK if you have the larger (360 MB) distribution of JEE (Java Enterprise Edition), which contains the full Java SE JDK in its jdk subdirectory. Be aware that the JEE installation installs the unneeded applications server called Glassfish, which can interfere with tomcat, the applications server we will be using, by tying up port 8080.
·
You do not need to download
the "Java EE" version (see just above).
·
You do not need to download
the "with JavaFX" version. JavaFX is a "rich client" platform,
i.e., Java on
the client side for a web app.
·
You do not need to download
the "with NetBeans" version. NetBeans is an IDE that some people
use instead of eclipse.
You can use it if you want, but I can help you more easily
with
eclipse.
·
You do not need to download
the JRE (Java Runtime
Environment) It is included
in the JDK download.
·
Note:
Sun does not support Mac OS,
but recent Mac OS versions come with Java 5+, usable for at
least the first
part of the course. Try "javac
-version" at
the UNIX command line to check.
JAVA_HOME and Path:
Use System Control
Panel>Advanced>Environment to define the JAVA_HOME user
environment variable as c:\Program Files\Java\jdk1.7.0 or
c:\Java\jdk1.6.0_xx 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/ant setup test (use a brand new command window if you just changed your environment variables)
java -version should output
java version "1.7.0" or "1.6.0_xx" where xx is two digits
Eclipse 3.7
(Indigo): Eclipse for Java IDE for JEE Developers
Windows ant setup test:
Ant nuisance message:If
you get the error message "The system cannot find the
batch label specified
- end" after an ant execution, it is because of a Windows XP
bug. To fix
it, cd %ANT_HOME%/bin, and edit
ant.bat to add a few
blank lines or a REM statement before the line with :end.
Eclipse tricks worth knowing:
To rebuild 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.
Note on eclipse dot files: filenames starting with a dot are internal data for eclipse. You can always build a new project from your source files alone.
.project file in each project: If you want to start over on building an eclipse project from your source files, delete this file first if it's there. Otherwise eclipse will refuse to build a new project there, saying that the directory is already in use.
.eclipse directory in your home directory: This is where all the global information you've set up is stored. If eclipse won't start up, delete or rename this directory. You will have to redo all the eclipse setup (JDK, projects and tomcat, etc.), but at least you don't need to reinstall eclipse.
Javadocs for library calls in your
source code
When you are editing source code in eclipse, try mousing over a
call like System.println() and see how the Javadoc for the
method show up. If methods from (say) persistence.jar (the JPA
API) fail to show such Javadocs, you can fix this problem by
finding the persistence.jar icon in Project Explorer,
right-clicking it, choose Properties, then Javadoc Location, and
fill in http://download.oracle.com/javaee/5/api, or another
provider of these Javadocs. I found this URL by a Google search
for "EntityManager JEE 5", yielding
http://download.oracle.com/javaee/5/api/javax/persistence/EntityManagerFactory.html,
and
then trimming off the parts specific to the full name of this
class, javax.persistence.EntityManagerFactory.