We are using the Linux system pe07.cs.umb.edu. Make sure you can login
to it as soon as possible. We will use Java for programming and Maven
for building our programs.
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 and
maven. To make sure the java and maven are recent-enough versions, 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
openjdk version "1.8.0_275" or more recent version, plus two more lines of
text
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 invoke.
Add JAVA_HOME to your environment variables at cs.umb.edu.
Note that your home directory is the same on users.cs.umb.edu as on
pe07.cs.umb.edu, or any other Linux server in our network, so you can edit
.profile or create a new .profile file there to set up your environment
for any host on our network. Add this line to .profile in your home
directory (creating the file if not there already):
export JAVA_HOME=/usr
Then log out and in again to put it in action and then test it with
env|grep JAVA which should output
Linux at cs.umb.edu: Maven setup test: the command is
"mvn". Note that Maven depends on the JAVA_HOME setting set up above.
mvn -version should output
Apache Maven 3.3.9 or later
Downloading Java from Oracle - We will be using Java 8 or higher (except Java 9) 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 or higher. Note that the JRE (Java runtime environment) is not enough. Download and install the latest JDK (Java SE Development Kit) from https://www.oracle.com/java/technologies/javase-jdk15-downloads.html. For Windows, download the .exe installation tool and run it. For Mac, download the .dmg and run it. Java 15 can be used as a maintenance release of Java 8, 7 or Java 6 for normal Java programming. Since pe07 is running Java 8, expect to recompile your sources after transferring them to pe07.
If you already have the Java 8 or higher JDK downloaded from Oracle, that's good enough. Or you can get the open source version of Java 15 from https://jdk.java.net/15/.
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, in particular maven, our build tool.
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.
JAVA_HOME and PATH for a Windows machine: Use System Control Panel>Advanced>Environment to define the JAVA_HOME user environment variable as c:\Program Files\Java\jdk-15.0.2 or C:\Program Files\Java\jdk1.8.0_xxx or wherever you have the JDK. There is a shortcut method to get to this control panel, as follows. Click the Start button, fill in "envir" in the text box, and click on "Edit Environment Variables for your account", add JAVA_HOME as c:\Program Files\Java\jdk-15.0.2 or wherever you put the JDK download.Then edit your user Path environment variable to include your JDK's bin directory, using %JAVA_HOME%\bin as its value, or the explicit path such as C:\Program Files\Java\jdk1.8.0_xxx\bin. 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.
JAVA_HOME and 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, add this line to .profile (creating the file .profile if not there already):
export JAVA_HOME=/usr
If you have downloaded Java to /usr/local/jdk11.0.2 (say), then put "export JAVA_HOME=/usr/local/jdk11.0.2"; in .profile. 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. The straightforward way is to edit your PATH environment variable setup in .profile. Suppose the old PATH (reported by "echo $PATH";) is :/usr/local/bin:/bin:/usr/bin Then add this line to .profile:
export PATH=$PATH:/usr/local/jdk11.0.2 /bin
Note the colons between directories on the PATH, vs. semicolons for the Windows PATH. If java and javac are in /usr/bin, you don't need to modify the PATH because it already has this driectory.
This should be executed when you open a new shell window, but if that doesn't work, you can execute it explicitly by "source .profile".
Test the environment variables by creating a new shell window and using the "env" command, or for example "echo $JAVA_HOME";.
JAVA_HOME and 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 of the .dmg and its installation, you should have java and javac available in /usr/bin, same as many Linux systems.
export JAVA_HOME=/usr in .bash_profile in your home directory. Don't put spaces around the = sign.
Then create a new Terminal (flower-N is the shortcut) 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. However, we also need to use environment variables inside eclipse, a GUI program normally executed from an icon in the dock. There is no single way to set up global environment variables for all recent versions of Mac OSX. Instead, what we can do is either run eclipse from Terminal (cd to the directory containing file "eclipse" and use eclipse, or possibly ./eclipse, as a command), or wrap it in a shell script and put the shell script in the dock. See "eclipse on Mac" below.
Note: use a brand new command window or shell if you just changed your environment variables.
1. Windows set|find "JAVA" should
output
JAVA_HOME=c:\Program Files\Java\jdk-15.0.2
or whatever you specified as the JDK directory
Linux/Mac: env|grep JAVA should
output
JAVA_HOME=/usr
unless you are using a distribution in another area.
2. On Windows, the path
command 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\jdk-15.0.2\bin. On Linux or
Mac OSX, echo $PATH outputs the current PATH variable. And in
Mac/Linux, for a single executable, you can use the which
command
to see where the executable is found, so for example "which java" should
return /usr/bin.
3. java -version should output:
java version "15.0.2" if new, or if Java 8, "1.8.0_xxx" or similar where xx is two or three digits
Windows Failure case: All set up as above, but java
-version shows java 1.7.x (or some other wrong version). Look for a
java.exe in C:\Program Files (x86)\Common Files\Oracle\Java\javapath
directory. Delete it or 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.7.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.
4. javac -version
should output the same version, say
javac 15.0.2
or matching java's version
if Java 8
5. 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.
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.
As discussed under environment variables above, it is challenging to get environment variables to work inside Mac applications launched from the dock. You can launch eclipse from Terminal by using the "open -a" command, so "open -a Eclipse", assuming Eclipse.app is in your Applications directory. This way, your environment variables will be defined inside eclipse.
The useful command "Open projects from file system" may not be obvious on the Mac. It's available from the menu bar at the top of the screen.
Eclipse tricks worth knowing:
Maven 3.6.3
Download maven from https://maven.apache.org/download.cgi, using the binary zip archive. You should already have the needed JAVA_HOME environment variable set up, discussed under the Java setup above.
On Windows, download the zip and expand it into some convenient directory, say c:\apache-maven-3.6.3. Then edit your PATH environment variable to include c:\apache-maven-3.6.3\bin.
On Mac and Linux systems, download the zip and expand it the default way, which does its work in Downloads. Then use the shell/Terminal to "cd Downloads" from your home directory and "ls" and you should see a directory apache-maven-3.6.3. Move it to your login directory with "mv apache-maven-3.6.3 ..". Then edit your .bash_profile (Mac) or .profile (Linux) to be:
export JAVA_HOME=/usr
export
PATH=$PATH:/Users/yourusername/apache-maven-3.6.0/bin:.
(that's a colon, then a dot at the end)
The inclusion of . on the path allows you to run scripts in a directory by their simple names, like "runit.sh" rather than needing to put "./runit.sh" for example.
For more information on installation, see http://www.mkyong.com/tutorials/maven-tutorials/
Maven Test
mvn -v should output its version 3.6.3, etc.
The needed Maven pom.xml files for projects will be supplied, and probably do not need to be edited, but it is important to understand their basic operation. This will be covered in class. Eclipse supports maven, and marks a project with an M if it sees a pom.xml in it. Whenever you edit pom.xml, you need to update your eclipse project by project>right-click>Maven>Update Project.
Eclipse and Maven
A maven project in eclipse gets access to the Maven repository of jar files. To get the best development and debugging environment, go to Window>Preferences>Maven and check Download Artifact Sources and Download Artifact Javadoc. Then eclipse will know the method signatures of the methods of the libraries in use (except for some that appear to be without available Javadoc), support code completion, and even let you dive into the library sources using the debugger.
Maven on pe07.cs.umb.edu possibly causing over-disk-quota problem
Sometimes the maven repository, situated by default at ~/.m2/repository
(.m2 is a dot file, so use ls -a to see it), gets so large that it runs
your account over your diskspace quota. In that case, you need to relocate
it to ~/cs636/repository by putting a file named settings.xml
in ~/.m2 with contents:
<settings>
<localRepository>/home/username/cs636/repository</localRepository>
</settings>
This will place it in the diskspace allocated for cs636 work, not under
your personal quota.