CS636 Java/Ant Development Setup: on UNIX/Linux and on your home PC, Spring ‘13

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". We are using Oracle on dbs2.cs.umb.edu, a Sun Solaris system, and mysql on sf08.cs.umb.edu, a Linux system.

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.

To define the JAVA_HOME and ANT_HOME environment variables, put these lines in your .profile:

ANT_HOME=/tools/apache-ant-1.7.0; export ANT_HOME

JAVA_HOME=/usr; export JAVA_HOME

SunOS Setup (optional). The only SunOS system we really need to use is dbs2.cs.umb.edu, our Oracle server, and we don't need to use it for Java compiles or program executions. For this class, it is probably simpler to just use our Linux server sf08 for editing and running programs, as well as home systems.  If you do want to use our SunOS systems for Java development, 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.

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 to the UNIX/Linux filesystem.

UNIX/Linux  java setup test: 

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=/usr  (on sf08, Linux)    (JAVA_HOME= /tools/jdk-1.6.0_03/usr/jdk/jdk1.6.0_03 on SunOS)    

env|grep CLASSPATH    should output nothing.  If it does give output, try to hunt down the source, usually in .profile on Linux (or .cshrc on SunOS) 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 (Juno release of summer, 2012): Eclipse IDE for Java EE Developers

  1. Install the "Eclipse IDE for JEE Developers" from www.eclipse.org. This also free. Put it in (say) c:\eclipse-jee-juno-win32.  If you have an older version of eclipse, upgrade now, because each new version has important new features and fixes. Try out eclipse as a Java IDE if you don't already know it.
  2. 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.
  3. Add ECLIPSE_HOME as an environment variable (in the System control panel) with value, for example
        ECLIPSE_HOME=c:\eclipse-jee-juno-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.4
        Define ANT_HOME as an environment variable (in the System control panel) with value, for example
            ANT_HOME = c:\apache-ant-1.8.4
        Then add %ANT_HOME%\bin to your Path environment variable.

        Windows ant setup test:

ant -version     should output
Apache Ant(TM) version 1.8.4 ...

set|find "ANT"    should output
ANT_HOME=c:\apache-ant-1.8.4\bin
path  should output ... ;C:\apache-ant-1.8.4\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.