CS636 Java/Ant Development Setup: on UNIX/Linux and on your home
PC, Fall 2011
UNIX/Linux Java setup.
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".
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. We will be using the Linux server sf08.cs.umb.edu,
which runs the mysql database.
SunOS Setup. 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". To activate your new .cshrc settings, use
"source .cshrc", or log out and in again. The only SunOS system we
really need to use is dbs2.cs.umb.edu, our Oracle server.
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
Home PC Setup
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 we will not be
using.
- 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.
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
Java(TM) SE Runtime Environment (build
1.7.0_0x-xxx)
Java HotSpot(TM) Client VM (build
1.7.0_0x-xxx, mixed mode, sharing)
javac -version
should
output
javac 1.7.0
set|find
"JAVA"
should output
JAVA_HOME=c:\Program Files\Java\jdk1.7.0
or whatever you specified as the JDK directory
cd %JAVA_HOME%
dir
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.
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\Java\jdk1.7.0\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.
Eclipse 3.7 (Indigo): Eclipse for
Java IDE for JEE Developers
- Install the "Eclipse IDE for JEE Developers" from www.eclipse.org.
This also free. Put it in c:\eclipse-indigo-win32. If
you have an older version of eclipse (3.6 or older), upgrade
now, because this new version has important new features. Try
out eclipse as a Java IDE if you don't already know it.
- Make sure eclipse sees your Java 6 or 7 JDK by visiting
Window>Preferences>Java>Installed JREs, and looking
for the Java JDK. If it's not there, click the Add button, and
fill in:
JRE name: jdk6 or jdk7
JRE home directory: c:\Program
Files\Java\jdk1.7.0 or ...
and clicking OK. Then make sure it is checkedcd as the
default JRE in the "Installed JREs" window you should return
to.
- Add ECLIPSE_HOME as an environment variable (in the System
control panel) with value, for example
ECLIPSE_HOME=c:\eclipse-jee-indigo-win32\eclipse
ant.
Download ant from http://ant.apache.org/bindownload.cgi,
say as a zip archive, and unzip it to c:\apache-ant-1.8.2
Define ANT_HOME as an
environment variable (in the System control panel) with value, for
example
ANT_HOME =
c:\apache-ant-1.8.2
Then add %ANT_HOME%\bin to
your Path environment variable.
Windows ant setup test:
ant -version
should output
Apache Ant(TM) version 1.8.2 ...
set|find
"ANT" should output
ANT_HOME=c:\apache-ant-1.8.2\bin
path should
output ... ;C:\apache-ant-1.8.2\bin; ...
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.
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.
Putty Tunnel Needed to access
Oracle on dbs2.cs.umb.edu
Our departmental firewal blocks port 1521 needed for jdbc access
to Oracle. To get around this, we set up a putty tunnel so that
the data actually goes through the firewall using port 22, the
unblocked ssh port.
1. Download putty.exe from
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
to your development machine.
2. Run it and see the "PuTTY Configuration" window. Expand the SSH
entry and see "Tunnels", and click on it.
3. Enter 2222 as Source Port and dbs2.cs.umb.edu:1521 as
Destination, and click the Add button.
Image
4. Select the Session entry in the Category list. Type dbs2tunnel
under Saved Sessions and click the Save button.
Image
5. Click Open to test it. Log in with your UNIX password.
6. Now you can connect to Oracle on localhost:2222, that is, host
"localhost", port 2222. Just leave the putty tunnel's window in
some corner of your screen so you can tell if it has lost its
network connection. It will handle multiple JDBC connections to
Oracle as long as it is connected.
Later, to use it again, run putty and double-click the name
dbs2tunnel, log in.
Test of Putty Tunnel: use
your own Oracle account, of course
C:\cs\cs636\jdbc>java -cp ojdbc6.jar;.
JdbcCheckup
Please enter information to
test connection to the database
Using Oracle (o), MySql (m)
or HSQLDB (h)? o
user: cs636test
password: cs636test
use canned Oracle connection
string (y/n): y
host: localhost
port (often 1521): 2222
sid (site id): dbs2
using connection string:
jdbc:oracle:thin:@localhost:2222:dbs2
Connecting to the
database...connected.
Hello World!
Your JDBC installation is
correct.