The Best
The Best

Reputation: 361

Debugging SBT project with Play in IntelliJ IDEA

I have a SBT project

in this project i have a sub play project and other projects

example from my build file :

 lazy val subProj1 = Project(id = "sub-proj-1", base = file("sub1"))
.settings(...)...

 lazy val subProjPlay =  play.Project("play-proj", 1.0 , path = file("web"))

need to debug the play server from IntelliJ IDEA.

To run the project I use sbt run on the command line.

How can I debug the project in IDEA?

Upvotes: 19

Views: 16489

Answers (4)

Yuriy Tumakha
Yuriy Tumakha

Reputation: 1570

The easiest solution.

  1. Edit Configurations... -> add SBT Task (not Remote task). Specify SBT Task: ~run.

  2. Run created SBT Task using - Debug Debug button

Upvotes: 13

BaiJiFeiLong
BaiJiFeiLong

Reputation: 4609

IntelliJ IDEA 2016.1.1 && Play Framework 2.5.3

For me, no matter how I set(create new Run/Debug Configuration for Play 2 App or SBT Task, specify the debug port, execute in Run or Debug mode) in the IntelliJ IDEA 2016.1.1 Enterprise Edtion, the IDEA can not open the debug port(default 9999), so the debug is impossible.

After disable the sbt-fork-run-plugin(comment it in /project/paly-fork-run.sbt), it works!!!

I am newer to Play framework,and have found many bugs...Compare to RoR, it's so hard to learn, to run, to use, to debug...

Below is my steps:

  1. disable the sbt-fork-run-plugin(comment it in /project/paly-fork-run.sbt)
  2. execute activator -jvm-debug 9999 "run 11111" (I use port 9999 to debug, port 11111 to run my Play project)
  3. In IDEA, add an new Run/Debug configuration, Choose, set debug port to 9999
  4. debug the new created configutation

Upvotes: 1

Jacek Laskowski
Jacek Laskowski

Reputation: 74599

Provided you've Play distribution installed locally, use play debug run on the command line and connect to localhost on the port 9999 in IDEA.

From Debugging section in Using the Play console in the official Play 2.2.x documentation:

You can ask Play to start a JPDA debug port when starting the console. You can then connect using Java debugger. Use the play debug command to do that

If however you don't have it (and for a reason don't want to install it), add Remote Run configuration in IDEA that will give you a hint for the command line arguments you should be using when launching SBT, e.g.

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

When you launch SBT that may or may not be as simple as launching SBT jar, just use the above to configure JVM to run in debug mode.

Upvotes: 2

Nimrod007
Nimrod007

Reputation: 9913

I found this to be the easiest solution : (using IntelliJ IDEA )

in IntelliJ :

Go to "edit run configurations"

enter image description here

Create a new remote configuration (port 9999, all other details leave with default values)

enter image description here

Go back to IntelliJ and run the new debug configuration (don't forget to put a break point)

From command line run :

 sbt -jvm-debug 9999 run

Upvotes: 35

Related Questions