Lab 2 Setup: Setting Up IntelliJ

Prerequisites

  1. Java 8 - You finished lab 1b
  2. You have successfully created your local repo for the class on your own machine. This is the 3-letter directory you created and set up in lab 1.
  3. You have pulled from skeleton master, and you have a lab2setup directory in the same directory as your lab1 and proj0 folders.
  4. Be mentally prepared to use a real world software development package. It will seem very complicated for a while, but we'll lead you down the narrow path to success. Ask for help if you are stuck! It can be very hard to guess the right thing to do in IntelliJ.

Installing IntelliJ

If you're working on the lab computers, skip this step.

  1. You'll need to install the Community Edition of IntelliJ from the Jetbrains website.
  2. After selecting the appropriate version for your OS (Mac OSX, Windows, or Linux), click download and wait a few minutes for the file to finish downloading.
  3. Run the install file and follow the prompts to install IntelliJ onto your computer. You can stick to all the default settings. Feel free to install IdeaVim if you're a vim user.

Installing the IntelliJ CS 61B Plugin

Begin the setup process by starting up IntelliJ. If you're on one of the lab computers, use the command /share/instsww/bin/idea.sh in a terminal window to start IntelliJ. Then follow the steps below.

  1. In the Welcome window, click the Configure -> Plugin button on the bottom right of the window.
  2. Click the button labeled Browse Repositories... on the bottom. Browse Repositories
  3. In the window that appears, enter "CS 61B" in the search bar at the top. The CS 61B plugin entry should appear.
  4. Click the green Install button. Browse Repositories
  5. Wait for the plugin to download and install
  6. Click the grey Restart IntelliJ IDEA button to finalize the installation.

For more information on using the plugin, read the plugin guide. You can skip this reading for now.

Project Setup

IntelliJ is an IDE (Interactive Development Environment). It's like a text editor (i.e. Sublime) but it's chock full of extra features. In order to run your files in this special environment where we can work our IDE magic, we need to import our files into a project, similar to how you might import images or clips into a project for a program like iMovie or Windows Movie Maker. Fortunately, this is a fairly painless process.

These instructions apply for both initial setup and for future assignments. When you run git pull skeleton master to retrieve a new assignment and you notice that you have a new assignment directory (next week, you'll have lab3/) simply run through these steps again from 1 to 8. This will likely involve pressing next for all steps and, if IntelliJ asks you to overwrite various housekeeping files (such as .iml files) because they already exist, respond "Yes" or "Overwite" to those popup windows. This is so IntelliJ can automatically mark the new directories for your assignment to work with IntelliJ for you as opposed to you manually marking directories as source folders and/or modules.

Begin the setup process by starting up IntelliJ. If you're on one of the lab computers, use the command /share/instsww/bin/idea.sh in a terminal window to start IntelliJ. Then follow the steps below.

  1. Upon opening IntelliJ, click on the "import project" option. IntelliJ Start Menu
  2. Find and choose your lab2setup directory, then press the OK button. From here on out, you should be able to simply select next for every screen but to be safe in the face of shenanigans, more screenshots follow. If you keep clicking next without paying attention and get to a point where you see a message that says No SDK specified, stop and consult step 8! y IntelliJ Select Folder
  3. Make sure "Create project from existing sources" is selected and press next. You shouldn't have to change anything at this step. Import Project
  4. Leave these fields untouched and press next. Project Name
  5. Do nothing here and press next. For context, IntelliJ is automagically detecting what your Java files are and self-configuring itself to edit and run them. Import Sources
  6. You may not actually see this next window pop up. If it does, click next. If it doesn't, that's fine. Import Sources
  7. You may not actually see this next window pop up. If it does, click next. If it doesn't, that's fine. Import Sources
  8. You may not actually see this next window pop up. If it does, and you see 1.8 on the left sidebar, you're in the clear and can simply press next then click finish on the final screen and voila, your project is set up and you can skip steps 9 and 10! Otherwise, continue on to steps 9 and 10. Select SDK
  9. Click the plus in the upper left corner and click jdk from the drop-down menu Add JDK
  10. Find where your jdk is saved, select it, and press ok button. On my Mac, it was at /Library/Java/JavaVirtualMachines/jdk1.8.0\_60.jdk/Contents/Home. If you're on Windows, your path may look like C:\Program Files\Java\jdk1.8.0\_60. If you're on a lab computer, it should be at "/usr/lib/jvm/Java-8-oracle/". Once this window closes and your screen looks like the image at step 8, press next, then finish, and you're done! Select JDK

Once you've pressed finish, you should see something really similar to the following image. You may need to click the little triangle next to lab2setup in the top left to get the source files (Dog.java and TestDog.java) for lab2setup to show up. Select JDK

Relax for a Bit

The first time you start up IntelliJ it's going to spend some time indexing files. This may take a few minutes. There should be a little progress bar in the bottom right. Once it's done, a sidebar will appear.

Importing Libraries and Running Code

Double check on TestDog.java. You should see that some of the words in the file are red, specifically Test and assertEquals. If you mouse over them, you'll see a message along the lines of "cannot resolve symbol". The trouble is that we haven't told IntelliJ where to find the CS61B libraries.

Click File - Project Structure in the top left of IntelliJ. A window should pop up, and you should click "Libraries" on the left panel of this window. When you've done so, it'll look as shown below: project structure

Click the green plus in the top left of this window and pick Java from among the given choices. This will pop up a window. Click on the javalib folder, at which point your window should look something like below: library files

Press OK a few times, and you'll find yourself looking at DogTest.java again. This time, the red text should be gone. Try running the code by clicking Run - Run, as shown below. library files

This will probably pop up a very small dialog window like the one shown. Basically IntelliJ is saying that it isn't quite sure what you mean by running the program and is giving you two choices: 0. is to edit the configuration before running the program (which we won't do). 2. is to run the DogTest class, which is what we want. library files

Click on DogTest and a green bar should appear with the message "All 2 tests passed." as shown below. library files

You'll notice after running your code that the green play and green bug icons in the upper right are now green; this is because when you clicked "2.", IntelliJ memorized what you meant by Run for this project and you can now click this button to run your program. You'll learn more about this over time as we use more advanced features of IntelliJ.

Embedded Terminal (Optional)

IntelliJ has the cool feature that you can have a working terminal in the workspace so you don't have to constantly switch between having IntelliJ and your terminal, if that becomes necessary for whatever reason.

For Mac users, you should be able to skip this setup section. Windows users will likely have to put in a little leg work. This setup assumes you are a Windows user and you have git bash installed.

First, find the preferences/settings tab and select it (Or use Ctrl+alt+s) Preferences

Type in "terminal" in the search bar. Once there, type in "C:\Program Files (x86)\Git\bin\sh.exe" --login -i into the Shell Path field. Click ok.

Terminal

To test if you've properly set this up, hover over the little box in the bottom left corner and select terminal; the bottom third of your screen should now be a terminal, the equivalent of having git bash right there.

Terminal Test

Try typing something in! If you're able to run basic commands like "ls" or "cd" or "echo 'Hello world'" you've done it!

Terminal Test