For programmers who would like to use IntelliJ IDEA with this course.
You need to watch the first lecture of this course, and to install the software described in that lecture before attempting to follow these instructions. You need the IDEA 12 Ultimate Edition to work with the projects provided with this course. JetBrains offers a 30 day trial for IDEA Ultimate. This lecture was produced with IDEA 12.1.3.
Under Mac and Linux, and Windows with Cygwin, you can launch IDEA like the following. Be sure that
JAVA_HOME is set. Of course, the directory you installed into will likely be different:
/opt/idea-IU-129.161/bin/idea.sh > /dev/null 2>&1 &
When IDEA starts for the first time, it will run the Initial Configuration Wizard, and ask for the plugins that you want to enable. I have not noticed issues with having lots of unnecessary plugins enabled, and you can disable plugins easily at any time, so you should press the Skip button and move on.
HTML / File reference problems (so Play templates do not have a lot of complaints over missing files)
Scala / Method signature / Method with Unit result type defined like function
Scala / Method signature / Method with Unit result type defined with equals sign
I turned these warnings on:
Scala / General / Relative import
XX:MaxPermSizewill help compile large projects faster. My settings are:
Enable Show line numbers
Change the Theme to Darcula. IDEA will restart.
If you are used to the Eclipse IDE's shortcut keys, you can use them with IDEA by setting them from File / Settings / Keymap. Select the predefined Eclipse keymap.
Editor - uncheck Allow placement of caret after end of line.
Back arrrow, you now see the Configure menu
You can use
jvisualvm, provided with the Java Development Kit, to measure memory usage of the IDE, so you can optimize the memory settings. The VisualVM site has many articles that discuss how to use the tool. I suggest that you do not use the VisualVM IDE plugin to measure the IDE that it runs from, and instead run the tool standalone!
In the IDEA installation directory, edit
bin/idea.vmoptions. My development machine has 32 GB RAM, and I use that memory to run several virtual machines simultaneously. Each VM has 7 GB RAM. Here are my settings:
-Xms1128m -Xmx2512m -XX:MaxPermSize=500m -XX:ReservedCodeCacheSize=164m -XX:+UseCodeCacheFlushing -ea -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true
At the command line, navigate to the
oocomp_code directory. It contains two directories, called
To export the
courseNotes sbt project to IDEA, change to the
courseNotes directory and run this command:
If this is the first time you run sbt with this project, you will have to wait several minutes while many dependencies are downloaded. Eventually you will see something like:
[info] Loading global plugins from C:\Users\Mike Slinn\.sbt\plugins [info] Loading project definition from C:\scalaJavaInterop\ooCompat\courseNotes\project [info] Set current project to scalaJavaOOCompatCourse (in build file:/C:/scalaJavaInterop/ooCompat/courseNotes/) [info] Trying to create an Idea module scalaJavaOOCompatCourse [info] Excluding folder target [info] Created C:\scalaJavaInterop\ooCompat\courseNotes/.idea/IdeaProject.iml [info] Created C:\scalaJavaInterop\ooCompat\courseNotes\.idea [info] Excluding folder C:\scalaJavaInterop\ooCompat\courseNotes\target [info] Created C:\scalaJavaInterop\ooCompat\courseNotes\.idea_modules/scalaJavaOOCompatCourse.iml [info] Created C:\scalaJavaInterop\ooCompat\courseNotes\.idea_modules/scalaJavaOOCompatCourse-build.iml
Now change to the the
assignment directory and run the same command:
Again, output should look something like:
[info] Loading global plugins from C:\Users\Mike Slinn\.sbt\plugins [info] Loading project definition from C:\scalaJavaInterop\ooCompat\assignment\project [info] Set current project to scalaJavaOOCompatAssignment (in build file:/C:/scalaJavaInterop/ooCompat/assignment/) [info] Trying to create an Idea module scalaJavaOOCompatAssignment [info] Excluding folder target [info] Created C:\scalaJavaInterop\ooCompat\assignment/.idea/IdeaProject.iml [info] Created C:\scalaJavaInterop\ooCompat\assignment\.idea [info] Excluding folder C:\scalaJavaInterop\ooCompat\assignment\target [info] Created C:\scalaJavaInterop\ooCompat\assignment\.idea_modules/scalaJavaOOCompatAssignment.iml [info] Created C:\scalaJavaInterop\ooCompat\assignment\.idea_modules/scalaJavaOOCompatAssignment-build.iml
gen-idea command creates two directories, named
.idea_modules. Both of these directories should be mentioned in the
.gitignore file. You can examine the
.gitignore files provided with the projects for this course.
When finished, go back to IDEA and File / Open the directory. The Scala project should load into IDEA. We can now finish setting up IDEA. You will notice a small rotating icon at the bottom of the IDEA window, and the word Indexing... next to it. The first time IDEA encounters a new jar, such as found with a new JDK, it will index the jar. This can take a while, and the process might slow down your computer noticeably.
There is a vertical button at the upper left of the IDEA window, labeled Project. Click on that button and you will see the files and directories that comprise your project. The top two directories are the
.idea* directories; normally you should not need to look inside. The
project directory contains the sbt project files and directories. The
src directory contains your source code, including Java and Scala code, and can also include resources. The External libraries directory is presented to you by IDEA so you can browse the project dependencies. These files actually reside in
~/.ivy2. Note that there are two versions of the Scala compiler: 2.9.x and 2.10.x. The build system still uses 2.9.x but your code is compiled with Scala 2.10.1.
We need to configure the project structure before we can compile. File / Project structure opens a new window, and the Project SDK is probably invalid. You need to tell IDEA where your Java compiler is, so click the New... button, select JDK and navigate to the directory that you installed the JDK. Click the Apply button at the lower right of the window. We are done with Project Settings.
The menu item Build / Rebuild Project does not do a proper clean. If you really want to do a clean build, go to the command line, and type
sbt clean, or type
play clean for a Play Framework web application. While IDEA builds, you will see the status line at the bottom of the screen shows all the actions performed. The lower left of the screen displays the information that the FSC build server is being used, with v2.10.1 of the Scala compiler. Now let's run the program.
The easy way to run the program is to right-click on a Java file that contains a
main() method or a Scala file that defines an
object that extends
App. For example, let's run the Scala console application in
courseNotes/src/main/scala/com/micronautics/scalaJava/ScalaJava.scala. To do that, right-click on the file You will see three green icons, for running or debugging the program. When you use one of these menu items, a run/debug configuration is automatically created that you can edit. The Run or Debug console appears when you run the program, and output appears there.
The configuration file can be written to disk by clicking share, then OK. This creates a file in
.idea/runConfigurations that you can save to git if you like:
git add -fA .idea/runConfigurations
You may find that the editor does not parse complex Scala code or Play templates properly. If this happens you will see lots of good code highlighted as errors on the screen, and cutting and pasting may work improperly. You can temporarily toggle the Scala for the editor parser off and on by clicking in the small
[T] symbol at the bottom right of the screen, in the status bar area. When Scala parsing is disabled, the symbol displays as
If you have set up Eclipse keyboard shortcuts as described, the following extra keyboard shortcuts are specific to IntelliJ IDEA. The Key Promoter and Shortcut Keys List plugins are helpful for learning IntelliJ keyboard hot keys.
Alt + = Shows the inferred type of the highlighted variable or expression.
Ctrl + hover Shows summary of all kinds of useful information about artifact under cursor.
Ctrl + Space Code completion.
Ctrl + B Rebuild project.
Ctrl + Shift + A Find Action (learn key bindings, or do unbound actions)
Ctrl + Alt + V Create a variable from an expression.
Ctrl + Shift + B Toggle breakpoint on current line.
Alt + Shift + K Show default IntelliJ IDEA key bindings, requires Shortcut Keys List plugin.
Ctrl + Shift + J Join lines.
Ctrl + Shift + V Past from 5 most recent copies.
The following are some of the keys defined when you enable Eclipse key bindings.
Ctrl + D Delete line.
Ctrl + E and Ctrl + Shift + E Show list of recent files.
Ctrl + F Highlight all occurrences of selected text, and optionally search in current directory.
Ctrl + H Find in project, or if a directory is highlighted in the project pane, restrict search to that subdirectory tree.
Ctrl + Alt + B Pop up list of overrides or implementations, or go to implementation if there is only one.
Ctrl + / Comment / uncomment current line (toggle).
Ctrl + Shift + / Comment / uncomment current selection (toggle).
Ctrl + Shift + F Reformat file or selected code.
Alt + Shift + R Rename artifact under cursor.
Ctrl + Shift + R List matching files anywhere in project, optionally open one. Can also specify a filter