What follows is the recommended and supported development configuration used in our class. Note that you may also choose to set up a development environment on your local machine by following these directions for Windows. A subset of these instructions will work for personal Debian-based Linux installs, and only minor variations are needed for Mac (use brew to install the various components, and I recommend Aquamacs instead of plain Emacs). We won’t be able to support issues which arise on your local machines, though the student members of the CSA who often congregate in 425 may be willing to help.
The configuration assumes you are either using one of the NUCs in the lab locally, or are remotely accessing the CS server called pi. In order to remotely access pi, do the following. If you are in the lab you can skip to the section on Software Configuration.
Accessing pi from your personal computer
Windows
- If you would like to use visual applications (such as the visual version of Emacs) install and run VcXsrv, an application which will allow you to use remote graphical Linux applications on Windows. While Emacs works quite well this way even from off campus, some other graphical applications are extremely slow this way. Note that Emacs also has a text-only version which runs from the terminal without a graphical interface.
- Download PuTTY if you do not have it already.
- Run PuTTY and enter the following:
Host Name: pi.cs.oswego.edu
If you’re planning to use visual applications, on the left side under Connection, expand the SSH item, then choose X11. Check the “Enable X11 forwarding” option. - click the “Open” button at the bottom of the window.
Enter your lab username and password when prompted. If you are prompted about an RSA key type ‘yes’.
You should now be connected to the pi server.
Mac
If you plan to use visual applications, such as the visual version of Emacs, install and run XQuartz. Then, follow the below Linux instructions.
Linux
- Open a terminal
- At the prompt, type:
1 |
ssh -X YOUR_USERNAME@pi.cs.oswego.edu |
Enter your lab username and password when prompted. If you are prompted about an RSA key type ‘yes’.
You should now be connected to the pi server.
Software Configuration
Most of the required software is already installed, we only need to make some minor additions and do some configuration.
If you do not already have an open terminal, open one. Then run emacs by typing the following into your terminal (note that lines beginning with # are comments):
1 2 |
#Run emacs emacs |
Note: The following instructions will assume you are using the graphical version of emacs. It’s perfectly possible to use the text-based version in the terminal, but you’ll need some more key commands to move around the window.
In the emacs window, press the Ctrl and x key, followed by Ctrl and f key. This is usually annotated as:
1 |
C-x, C-f |
The result of this is to tell emacs you would like to open a file. At the bottom of the window (in the minibuffer) it will say “Find file: ~/”. At this prompt type:
1 |
.emacs |
and press enter (be sure you include the period at the beginning of the file name!). What will load will likely be a blank file, but it may contain some text. Add the following to the top of the file:
1 2 3 4 |
;;; Add this at the top of the .emacs file: (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) |
This adds a repository to the package manager in emacs.
Save the file by hitting C-x, C-s. Then, exit emacs (C-x, C-c) and restart it.
Once emacs restarts, type:
1 |
M-x list-packages |
The M-x means “Meta and the x key” where the meta key is usually the Alt key on most keyboards (Option on Mac keyboards).
A list of packages will be displayed. Scroll down to JDEE and click on it. Choose to install it. JDEE will give us Java syntax highlighting and auto-indenting.
Your build environment is now configured!
Configuration Testing
In your second terminal create a new folder called csc241 in your home directory, and inside that a new folder called testproject. Then navigate into testproject.
1 2 3 4 5 6 7 8 9 |
# Go to your home folder cd ~ # Make some directories mkdir csc241 mkdir csc241/testproject # Change into the csc241/testproject directory cd csc241/testproject |
We will be using Gradle to handle the configuration of our Java projects. This will allow us to easily compile the project and to integrate plugins into the build process. We’ll be using the Error Prone plugin which will force you to avoid some coding mistakes which Java might otherwise not complain about.
In emacs, open the (new) file ~/csc241/testproject/build.gradle
This file will contain the configuration for the project.
In your build.gradle, add the following:
1 2 3 4 5 6 7 |
plugins { id "net.ltgt.errorprone" version "0.0.13" } repositories { mavenCentral() } apply plugin: 'java' |
This tells Gradle to use Java to build this project, and to use the Error Prone plugin. Save the file.
Gradle expects to find your source code under src/main/java, so make those directories in the terminal. Then, open the file ~/csc241/testproject/src/main/java/Main.java in emacs.
Create a “hello world” style program in that file and save it.
Back at your terminal, type
1 |
gradle build |
Gradle will then build your project. (Note you can see the other things you can ask Gradle to do by running gradle tasks.)
Now, assuming you had no errors you need to fix, change into the ~/csc241/testproject/build/classes/java/main directory and run
1 |
java Main |
Your program should run.
You can verify that Error Prone is working by adding something silly to your code, such as in the following example:
1 2 3 4 5 6 |
public class Main { public static void main(String[] args){ if (true == true) System.out.println("Testing!"); } } |
Even though this is completely valid Java code, Error Prone no longer allows it to compile.
Provided all of this works, you should be ready to start programming!