Sunday, March 29, 2015

Debug Play 2 Applications in Eclipse

Typesafe activator makes it easy to manage a Play project.  This note is based on Play 2.3.8 using activator 1.3.2.

Open a Play Project in Eclipse

To turn the Pay project into an Eclipse project, run activator to launch the console. Inside the console, execute

    eclipse with-source=true

The last argument is optional, downloading the source code of used libraries.

After importing the project into eclipse, you can verify that

    target\scala-2.11\classes-managed

is added to Java Build Path > Libraries.

During the development process, you may run into IDE problems like eclipse not recognizing your view classes. They generally can be resolved by re-running the eclipse command and then refreshing the eclipse project.


Remote Debug

Launch the Play application with remote debugging enabled as

    activator -jvm-debug run

This uses the default port number 9999 for remote debugging. Alternately, you can be explicit about the port number:

    activator -jvm-debug 9999 run

Afterwards, you can attach eclipse via remote debugging. From Run > Debug Configurations ...


The tricky thing is that activator may launch the application by forking another JVM. As a result, I was remote debugging activator instead of the launched Play application. This left me baffled for quite a while: Eclipse attached correctly, but none of the breakpoints worked.

One easy workaround is to turn off the forking. Open build.sbt, set

    fork in run := false


1 comment:

Unknown said...

Thanks for mentioning => fork in run := false property. I was making this mistake.