Linux at cs.umb.edu: Java setup.
For Linux systems such as users.cs.umb.edu and our system,
topcat.cs.umb.edu, you should not need to do any setup to use java. To
make sure the java is a recent-enough version, simply use the commands
under Linux java and setup tests below. To check that java and javac
are in /usr/bin as expected, use the "which"; command as follows:
$ which javac /usr/bin/javac
Linux at cs.umb.edu: editors Hopefully you know emacs or
vi or another Linux editor. We will do most of our software
development on PCs, and then test the systems on Linux at cs.umb.edu for
final delivery. This works well because of the robust portability of Java.
Project deliveries are to the Linux filesystem at cs.umb.edu. See AccessToCSHosts.html
for more info on file transfers.
java-version should output
java version "1.7.0_xx", or more recent version, plus two more lines
of text, where xx stands for 2 digits
env|grep CLASSPATH
should output nothing.
If it does give output, try to hunt down the source, usually in
.profile or .bashrc, or files they invokes.
Downloading Java from Oracle - We will be using Java 8 (or Java 7) from Oracle. Everything we need from Oracle is in the Java SE (Java Standard Edition) download, that is, the JDK (Java Development Kit) for Java 8. Note that the JRE (Java runtime environment) is not enough. Download and install the latest JDK (Java SE Development Kit) from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html. 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 8 can be used as a maintenance release of Java 7 or Java 6 for normal Java programming.
If you already have the Java 7 JDK downloaded from Oracle, that's good enough. Also, it's OK if you have the larger (360 MB) distribution of JavaEE (Java Enterprise Edition), which contains the full Java SE JDK in its jdk subdirectory. Be aware that at least some JavaEE installations include the unneeded applications server called Glassfish, which can interfere with tomcat, the applications server we will be using, by tying up port 8080.
The environment variable JAVA_HOME tells where the JDK is located on the system (Windows, Linux, or MacOSX). Specifically, it is the directory with a bin subdirectory containing java and javac. JAVA_HOME is used by programs (other than java and javac) that need access to resources in the JDK.
The environment variable PATH holds the search path used by the system (Windows, Linux, or MacOSX) to locate executables. When we add a new executable located in a directory not listed in PATH, we need to add its directory to PATH, so we can run the program from anywhere on the system. How to do this depends on the system as follows.
PATH for a Windows machine: Use System Control Panel>Advanced>Environment to define the JAVA_HOME user environment variable as C:\Program Files\Java\jdk1.8.0_xxx or c:\Java\jdk1.7.0_xx or wherever you put the JDK download. There is a shortcut method to get to this control panel, as follows. Click the Start button, fill in "env" in the text box, and click on "Edit Environmant Variables for your account". 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; Test the environment variables by creating a new command window and using the "set" command.
PATH for a Linux machine: It should work to add the environment variables to .profile (or .bashrc or .bash_profile possibly, non-Ubuntu Linux) in your home directory. For example, if javac is in /usr/bin, it's already on the PATH, so you don't need to do anything here. If elsewhere, add this line to .profile:
export PATH=$PATH:/usr/local/jdk1.8.0_60/bin (for example)
if you have downloaded Java to /usr/local/jdk1.8.0_60. Note the colons between directories on the PATH, vs. semicolons for the Windows PATH. Log out and in again and see if javac is now available. If you did the download through a package system like apt-get for Ubuntu, you may not need to do anything extra to get the new java and javac on your Path, so check the resulting versions by "java -version" and "javac -version". If these fail or show an old version, you need further work. Ubuntu/Debian Linux has "update-alternatives"; for handling multiple versions of Java on the system, but it is somewhat difficult to use.
PATH for a MacOSX machine: Don't even try to Google this topic (environment variables on Mac OSX), because you will only find a confusing contradictory morass.
From the Terminal application, i.e., the UNIX shell, MacOSX works very much like Linux, except that .profile is called .bash_profile. Put the following line in .bash_profile in your home directory, creating a new file if necessary. After download from Oracle, look in /Library/Java/JavaVirtualMachines for the exact directory name in the following JAVA_HOME value. The following shows the specification valid in August, 2016.
export
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/bin/
(replace 101 as needed to match)
export PATH=$PATH:$JAVA_HOME/bin
Then logout and in again and check by "echo $JAVA_HOME"; in Terminal. Try the Java setup test below. This will establish the needed environment variables for command line work, i.e., commands in Terminal.
Note: use a brand new command window or shell if you just changed your environment variables.
1. java -version should output:
java version
"1.8.0_xxx" where xx is two or
three digits
Java(TM) SE Runtime Environment (build 1.8.0_xxx)
Windows Failure case: java -version shows java 1.6.x (or
some other wrong version). Look for a java.exe in Window's system32
directory. Rename it to java_hold.exe (run CMD as administrator for
this by right-clicking its icon and selection "run as administrator", or
log in as Administrator and use Windows Explorer.)
Mac/Linux Failure case: All set up as above, but java
-version shows java 1.6.x (or some other wrong version). Look for java in
/usr/bin. Just rename it to java_hold (cd /usr/bin; sudo mv java
java_hold) . If it's not in /usr/bin, find it using "which java". This
will print out where it's found on the system search path.
2. javac -version
should output the same version, say
javac 1.8.0_xxx
3. On Windows, set|find "CLASSPATH" should output nothing.
Similarly, env|grep CLASSPATH should output nothing on Mac/Linux If
it does give output, look for an old environment variable setting and
delete it.