Getting started with IntelliJ

This tutorial will walk you through the steps to set up and start working with JavaNLP using JetBrains' IntelliJ IDEA. The first part gives the simplest set of instructions, for when you have Java 6 on your machine, and you exploit the checked in Eclipse project structure. The second set of instructions cover installing SoyLatte (to get JDK1.6, if you don't have an Intel Mac) and setting up everything by hand for checking out all of the 2008 JavaNLP reorganization as a multi-module project, including using Java 6 with it on the Mac. The third part is older material, some of which is now dated. (The useful older material should be integrated at some point.)

IntelliJ is fast. After using the bloated beast that is Eclipse, using IntelliJ makes my neural receptors hum with delight. Loading up and switching between projects is faster. Setting preferences is faster. Tweaking the classpath, refactoring, searching for references, and generating code coverage reports: all faster. -- macjavadev

Simple instructions for an Intel Mac with Apple Java 1.6 installed

These instructions set up the whole of the reorganized JavaNLP, using Java 6 to compile under IntelliJ IDEA 7.0.3 or higher under Mac OS X 10.5 or higher with Apple Java 6 installed. They exploit the Eclipse project structure checked into JavaNLP.

  1. If you have an existing JavaNLP checkout and want to use the same path, move or delete it.
  2. Download IntelliJ from here, if you haven't already. The open source community edition version is also currently available here. Drag the application to your applications folder.
  3. At some point you'll want to give IntelliJ more memory, so you may as well do it now. edit /Applications/IntelliJ IDEA 7.0.3.app/Contents/Info.plist and change the line:
    <string>-Xms16m -Xmx256m -XX:MaxPermSize=120m -Xbootclasspath/p:../lib/boot.jar -ea</string>
    to perhaps
    <string>-Xms32m -Xmx320m -XX:MaxPermSize=150m -Xbootclasspath/p:../lib/boot.jar -ea</string>
  4. Run IntelliJ. If you have an open project, do File | Close Project. You should see the Quick Start page with buttons on the left and Plugins on the right
  5. If you want to use Scala, you need to be using IntelliJ IDEA 8. Click on Open Plugin Manager, click on Available, find Scala, right click on it and select Download and Install or Update Plugin. Click Okay, twice. IntelliJ closes down, restart it.
  6. From the "Quick start" page that appears when no project is open, choose Check out from Version Control | Subversion. If you haven't done this before, press the + sign and add the path svn+ssh://jacob.stanford.edu/u/nlp/svnroot .
  7. Expand the tree list triangle down. You may get a request to enter your NLP username and password. Enter it and click Okay twice if you do. You should see trunk, click the triangle again, and you should see javanlp and scalanlp. Click on javanlp, and then press Checkout.
  8. Choose a local Destination directory. I choose /Users/manning/javanlp. You need to create it first so it is an existing directory to select. There's a little icon for that in the dialog. Click Okay. Have it check out HEAD recursively. Choose a subversion format. If still running Mac OS X 10.5, note that choosing 1.5 will mean that the local repository will be incompatible with the command-line version of svn (but I did it anyway). If you're running Mac OS X 10.6, you have svn v1.6, and life is good. Go and get coffee and wait a while.
  9. Say Yes when asked if you would like to create an IntelliJ IDEA project for the sources you checked out. Say that you want to import the project structure from an external model. Click Next. Choose Eclipse. Click Next. Select the projects directory (javanlp/projects), and click to Link created IntelliJ IDEA mdoules to Eclipse project files. Put test in the Detect test sources box. Click Next.
  10. The next dialog should show 5 selected Eclipse projects to import. Click Next. Name the project (e.g., JavaNLP). Click Finish. Drink your coffee.
  11. Go into Preferences. Under Project Settings, mark the test/src directories of the various projects as Test Sources. (The option where IntelliJ was meant to find them didn't work for me....) If you want the output classes in each module's classes directories (as set up in Eclipse), go to Paths in each module, and choose Use module compile output path, and select the classes directory of each module. Leave Exclude output paths checked. Click Okay. Under File/Directory Options, click the top Project line, and then click in the blank area under Encodings. A pulldown menu magically appears. Set it to UTF-8. Say Okay. Under Compiler, say to give it a Maximum heap size of 256 MB. Say Okay.
  12. Start coding

Instructions for running IntelliJ on a Mac after the 2008 reorganization

These instructions set me up with the whole of the reorganized JavaNLP, using Java 6 to compile under IntelliJ IDEA 7.0.3 under Mac OS X 10.5. I've now put in JavaNLP IntelliJ module specification files (*.iml) files. I think they may be used when you do the checkout, and so a few of these things you might no longer have to do (let me know if you try this).

  1. If you have an existing JavaNLP checkout and want to use the same path, move or delete it.
  2. Download SoyLatte from here. I installed the 32 bit binary (not enough memory in my Mac for 64 bit to be sensible....) Alternatively, it should also work to install the Apple Java SE 6 preview if you want.
  3. Unpack SoyLatte. I unpacked it in ~/Software, but anywhere should work.
  4. Download IntelliJ from here, if you haven't already. The open source community edition version is also currently available here. Drag the application to your applications folder.
  5. At some point you'll want to give IntelliJ more memory, so you may as well do it now. edit /Applications/IntelliJ IDEA 7.0.3.app/Contents/Info.plist and change the line:
    <string>-Xms16m -Xmx256m -XX:MaxPermSize=120m -Xbootclasspath/p:../lib/boot.jar -ea</string>
    to perhaps
    <string>-Xms32m -Xmx320m -XX:MaxPermSize=150m -Xbootclasspath/p:../lib/boot.jar -ea</string>
  6. Run IntelliJ. If you have an open project, do File | Close Project.
  7. From the "Quick start" page that appears when no project is open, choose Check out from Version Control | Subversion. If you haven't done this before, press the + sign and add the path svn+ssh://jacob.stanford.edu/u/nlp/svnroot .
  8. Expand the tree list triangle down to see trunk, and then again to see javanlp. Click on javanlp, and then press Checkout.
  9. Choose a local Destination directory. I choose /Users/manning/javanlp. Have it check out recursively. Sit back and wait a while.
  10. Say Yes when asked if you would like to create an IntelliJ IDEA project for the sources you checked out.
  11. Choose create Java project from existing sources. Call it javanlp. Take all the source files it has found. Take the libraries it finds. Except rename lib1 as mtlib (select and click on the pencil button). Take the Modules it finds. Except rename Test1 as RTETest. Finish. Wait again.
  12. Open up IntelliJ IDEA | Preferences.... Click on Project Settings. Under Project JDK, click New. Choose JSDK. Navigate to the one you installed and select it (the root directory). Choose OK. It will show up as 1.6 (1.6.0_03-p3) in the combobox. Choose 5.0 as the project language level. For Project compiler output, I changed out to classes, but whatever.
  13. In the same preferences window, under Project Settings, choose Modules, and then choose Core and then choose Dependencies. Remove the two libraries from mt/lib (fastutil-5.0.9.jar and bsh.jar). The first of these screws up compilation, because Core should use the more recent fastutil-5.0.10.jar. (This is something IntelliJ seems to do badly: it gives all libraries to all modules by default, rather than just the libraries that correspond to a module in the source tree organization.)
  14. In the same preferences window, under Project Settings, choose Modules, and then choose Core and then choose Dependencies. Change the Module JDK to 1.5. Then you'll still be able to run your Core package code with the standard Applie Java 5 runtime at the command-line.
  15. In the same preferences window, under Project Settings, choose Modules, and then right click RTETest and delete it. Choose Rte, and navigate to the src directory inside test and click Test Sources to label it as a Test Source directory. Similarly delete Test and then choose Core and navigate to the src directory inside test and click Test Sources to label it as a Test Source directory.
  16. In the same preferences window, under Platform Settings, select JDKs, and then look at the Classpath. Click "Add..." and navigate to the jre/lib subdirectory of your soylatte installation and multiselect all 6 jar files there and say OK.
  17. Click on Compiler. Change the amount of memory (at the bottom) to 256 MB. Say OK. Twice.
  18. Close preferences, and say Yes when it asks if you want to reload your project with the new language level.
  19. Choose Build | Make Project. Wait again. But it should work without errors (only warnings). Yippee!!.

Old instructions for installing IntelliJ and having a JavaNLP project

Download and Install IntelliJ

You can download IntelliJ for the operating system of your choice at http://www.jetbrains.com/idea/download/index.html. The copy comes with a 30 day trial license. If you like it and want to keep using it, talk to Chris about obtaining a license. The open source community edition version is also currently available at http://www.jetbrains.com/idea/nextversion/free_java_ide.html. It lacks a few features from commercial version, but is definitely usable. If you don't have a Java JDK, you need to download and install one from http://java.sun.com/j2se/1.5.0/download.jsp before starting to work with IntelliJ.

Create a Project

So really the only things you need to change are Name: and the path to your JDK. The rest of the defaults are fine. Now you've got an empty project. The next step is to download javaNLP.

CVS Integration

IntelliJ 4.0 and higher comes with CVS built in, so downloading the repository is a snap. In the sections that follow, JAVANLP_HOME refers to the module_content_root or the base directory of your local copy of the repository.

Classpath and Compiler options

Style Conventions

IntelliJ lets you specify all sorts of details about code formatting, including tab-width, spacing, newlines, when to use braces, alignment, and so forth. You can easily reformat an entire file to match your code style. We're not sticklers about whether you put a space after a comma in a list (although IntelliJ does let you specify this), but in order to make sure the code stays readable using the editor of your choice we strongly prefer that you use the same indentation standards as everyone else. These are: You can specify this yourself in Settings->Global Code Style or you can import the "official" javaNLP settings file. Just download this file (it's a .jar file because IntelliJ is written in java, but don't let that confuse you; just import it as directed here), and then select File->Import Settings and point the browser to the file.

Ant Integration

Although it's easy to compile your files with IntelliJ itself, IntelliJ also supports Apache Ant compilation for those who prefer it.

Miscellaneous Issues

Classpath changes

Using the Eclipse classpath integration in IntelliJ, after a .classpath change through svn, it seems like IntelliJ can get confused and lose your project sources. The easiest way to fix it seems to be to find the .classpath file, do svn revert, and the project will load all over again, and it will be right this time.

File Encoding

In order to make sure your file encoding is UNIX-friendly (so you don't get all those ^M's at the end of each line from Window's carriage returns), under Settings->IDE Settings->General, set the "Default Encoding" to UTF-8.

Excluding Directories from Compilation

If someone checked in some bad code that's breaking your compile, or you just want to speed up the compile time for the stuff you're working on, you can exclude files and directories from the IntelliJ compiler in the File->Settings->Compiler dialog.

JavaDoc Headers

When you create new files automatically with IntelliJ, it will make a JavaDoc file header for you. Unfortunately, this header won't even be proper JavaDoc format. Please go to Settings->File Templates and change it. (Hint: add an @author tag!) If you import our style settings file, this will be done for you.

Caret Placement

One IntelliJ default that I (personally) find annoying, is that if you click way off the end of the line, it allows the caret to go there, filling in the intervening space with space characters. You can turn this off in Settings->Editor->Virtual Space by unchecking the "Allow placement of caret after end of line" option.

Explore!

IntelliJ is a fully customizable, extremely flexible and powerful IDE. It has very useful capabilities for code navigation (e.g. type CTRL-b on any class or variable name to go to its definition), and refactoring (e.g. type CTRL-ALT-n to inline a variable or function, or SHIFT-F6 to rename a variable or class). You can change the key mapping to emulate emacs or Mac OSX. You can use and define your own quite sophisticated code-sensitive macros (try declaring a Collection and then type "itco" *TAB*). Time spent exploring and get used to using IntelliJ's advanced capabilities will be repaid ten-fold in terms of saved time coding in the future. (Not to mention reduced headaches!)

[ JavaNLP Project Home Page ]