Version 6, last updated by fbettag at 15 Mar 08:10 UTC

Here you will see how to debug a Lift application using SBT 0.11.2 and IntelliJ 11.

Preparation

I have to sbt scripts in my ~/bin/ directory, one is the regular sbt and then I have sbt-debug. In sbt-debug I simply added

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005

the complete script is:


java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005 -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=556m -Xmx768M -jar `dirname $0`/sbt-launch-0.11.2.jar "$@"

This tells sbt to start and listen on 127.0.0.1 port 5005. We will use this port from inside IntelliJ IDEA to connect the two and debug our Lift application.

sbt-idea plugin

You will also need the sbt-idea plugin, I included it in this sample project, but you can find more information about it on the project site

Sample project.

Just for this article, clone and start this sample application so we can both see the same thing:

git clone git://github.com/fmpwizard/lift-custom-wizard.git debugging-lift
cd debugging-lift
sbt
>gen-idea
>container:start

The gen-idea command will add the config info IntelliJ needs to recognize our project as an IDEA project.

IntelliJ setup

1- Open IntelliJ 11
2- Open our debugging-lift project (File – > Open Project – > Navigate to the project and click OK)
3- Click on Run – > Edit configuration
4- On the left side, you will see the word “default” above that you will see a little yellow plus sign, click on it and select “remote”
5- The only thing I change there is the “Name”, so look at the top of that screen and enter a name like “Lift-sbt” and then click OK

Debug!

1- Open the file src/main/scala/code/snippet/MyWizard
2- Scroll down to the method “thirdScreen” and do a regular click next to the line that has


“#name” #> NameVar.is &

if you click to the right of the line number, you should now see a red dot there, and the whole line is in a red highlight.
This means that when we run our application, and this line is reached, the debugger will stop execution and we can examine what is going on.
3- NOw go to Run – > Debug and select “lift-sbt”
4- a new window will appear at the button of the intelliJ screen saying something like:

Connected to the target VM, address: ‘localhost:5005’, transport: ’socket

5- On your browser go to http://127.0.0.1:8080/first
6- Fill in a name, press enter, fill in last name, press enter
7- Now the IntelliJ screen should be on the foreground, if not, go to IntelliJ
8- Our application stopped working right at the breakpoint we set before.
9- Now you can examine if our variables are correct, etc.
10- On the “Variables” panel, expand “this”
11- In my case I see lines like:
code$snippet$MyWizard$$firstName = (java.lang.String)"Diego"
...

This is just basically telling us that at this point, the var fuirstName has the value “Diego”

There are all kinds of things to explore here, like walking line by line by clicking on the “Step over” button, but you can simply read the help for IntelliJ to learn more (because it is not Lift specific any more)

When you are done you can press F9 and the program will continue to work.

Hope this helps.

Diego