CS680 Java/Ant Development Setup: on UNIX and on your home PC, Fall 2008

UNIX Java setup. Add modules java6 and ant/1.7.0 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 ant/1.7.0". 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:.

UNIX 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 4 other ANT_ environment variables

Home PC Setup:  for fall 2008

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 7 as of August, '08)  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.

      

      Alternatively, you can download the larger (360 MB) distribution of JEE (Java Enterprise Edition), which contains the full Java SE JDK in its jdk subdirectory. Install the  "Java EE + JDK" from Sun from http://java.sun.com/javaee/downloads/index.jsp.   I would put it in a top-level directory, say c:\Sun\SDK,  so  the jdk directory is  c:\Sun\SDK\jdk.The JEE installation can be run from a non-privileged user to ensure it can't touch the system files. The JEE installation will install the unneeded applications server called Glassfish, but if you install from an unprivileged user, cannot set it up as a system service. When it asks for you to specify a port, use 8888 instead of 8080 just to be sure it won't conflict with tomcat, the applications server more often in use at UMB..

      

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, or c:\Sun\SDK\jdk if you installed the JEE distribution. 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 digit
    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.

Eclipse 3.4: Eclipse for Java IDE for JEE Developers 
  1. Install the "Eclipse IDE for JEE Developers" from www.eclipse.org. This also free. Put it in c:\eclipse-whatever.  If you have an older version of eclipse (3.3 or older), upgrade now, because this new version 3.4 has important new features. Try out eclipse as a Java IDE if you don't already know it.
  2. 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 C:\Sun\SDK\jdk or ...
    and clicking OK.  Then make sure it is checkedcd as the default JRE in the "Installed JREs" window you should return to.
        ant.  ant version 1.7.0 comes with eclipse 3.4, so for command line use you just need to point to it properly.  
        Define ANT_HOME as an environment variable (in the System control panel) with value, for example
            ANT_HOME = C:\eclipse-jee-ganymede-win32\eclipse\plugins\org.apache.ant_1.7.0.v200803061910  
        Then add %ANT_HOME%\bin to your Path environment variable.

        Windows ant setup test:
ant -version     should output
Apache Ant version 1.7.0 ...

set|find "ANT"    should output
ANT_HOME=C:\eclipse-jee-ganymede-win32\eclipse\plugins\org.apache.ant_1.7.0.v200803061910  (or as needed for your eclipse directory)
path  should output ... ;C:\eclipse-jee-ganymede-win32\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\bin; ...

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 bug explained here. 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 Notes tricks worth knowing:
1. 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.
2. To get rid of warnings that build.xml has no DTD or schema (it never does), use Windows>Preferences>Validation>XML Validator, and add an exclusion by file name for build.xml.