Play 2.2.2 with IntelliJ 13 & SBT 0.13 cant run - No main class detected
Asked Answered
A

2

16

I'm trying to run one of the type safe activator projects in IntelliJ 13.1 with the latest Play 2 and Scala plugins.

I can run the project through the typesafe activator no problems but when I try to open the activator project via the build.sbt file in IntelliJ it all seems to work until I try to run the thing via the Play 2 App run configuration. I get the following error;

"C:\Program Files\Java\jdk1.8.0\bin\java" -Dfile.encoding=UTF8 -Djline.terminal=none -Dsbt.log.noformat=true -Dsbt.global.base=C:\Users\nw\AppData\Local\Temp\sbt-global-plugin5970836074908902993stub -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M -classpath C:\Users\nw\.IntelliJIdea13\config\plugins\Scala\launcher\sbt-launch.jar xsbt.boot.Boot run
    Getting org.fusesource.jansi jansi 1.11 ...
    :: retrieving :: org.scala-sbt#boot-jansi
        confs: [default]
        1 artifacts copied, 0 already retrieved (111kB/37ms)
    Getting org.scala-sbt sbt 0.13.0 ...
    :: retrieving :: org.scala-sbt#boot-app
        confs: [default]
        43 artifacts copied, 0 already retrieved (12440kB/109ms)
    Getting Scala 2.10.2 (for sbt)...
    :: retrieving :: org.scala-sbt#boot-scala
        confs: [default]
        5 artifacts copied, 0 already retrieved (24390kB/62ms)
    [info] Set current project to modules (in build file:/J:/DEV/TYPESAFE/reactive-maps/.idea/modules/)
    java.lang.RuntimeException: No main class detected.
        at scala.sys.package$.error(package.scala:27)
    [trace] Stack trace suppressed: run 'last compile:run' for the full output.
    [error] (compile:run) No main class detected.
    [error] Total time: 0 s, completed 02/04/2014 10:31:12 PM
    Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256M; support was removed in 8.0

    Process finished with exit code 1

My build.sbt looks like this;

name := """reactive-maps"""

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor" % "2.2.1",
  "com.typesafe.akka" %% "akka-contrib" % "2.2.1",
  "com.typesafe.play.extras" %% "play-geojson" % "1.0.0",
  "org.webjars" %% "webjars-play" % "2.2.1",
  "org.webjars" % "bootstrap" % "3.0.0",
  "org.webjars" % "knockout" % "2.3.0",
  "org.webjars" % "requirejs" % "2.1.8",
  "org.webjars" % "leaflet" % "0.7.2"
)

play.Project.playScalaSettings

Just running sbt run from the command line in the project folder works fine. So there is some issue with the way the SBT project has been imported.

Aile answered 2/4, 2014 at 11:36 Comment(2)
Might want to take a look at step 3 of the accepted answer to #16136216Putamen
Also, take a look at this.Korrie
P
10

Just ran into the same problem - my project is set up like so:

root/
  .idea/
  MainApp/ <-- this one is a Play 2.2.2 project
    .idea/
    apps/ <-- contains other Play2 projects

I was attempting to run the MainApp project and had the same problem.

If you notice in your run error: [info] Set current project to modules (in build file:/J:/DEV/TYPESAFE/reactive-maps/.idea/modules/)

states it is setting the project to modules. You want it to be reactive-maps.

Mine did the same - my quick solution:

-- find the file .idea/modules/reactive-maps.iml, move it to the root level reactive-maps/ directory.

-- Open the file, Ctrl-F Ctrl-R (find-and-replace)

-- Find: $MODULE_DIR$/../.. Replace with: $MODULE_DIR$/

Running the Play2 application again worked at this point.

The ideal solution would be importing it correctly (and I'm sure there is a way to do this), but this got my application running through IntelliJ quickly (although it will likely break on restart/SBT refresh).

Plumper answered 21/4, 2014 at 22:33 Comment(5)
From what I've noticed it happens when I import a project from existing module/sources (e.g. importing a project as an existing SBT module). Creating a new project from scratch always seems to workPlumper
:) Yep thats what I did.Jazzy
After applying your hack and after Idea restart it fails to open project. Idea complains about absent *.impl file in .idea/modules folderUlcerous
Interesting - I haven't seen that happen. I also re-structured my application so that I am no longer importing from existing sources/SBT module, which fixes the problem long-term.Plumper
Thank you. That worked for me. I also changed paths to modules' files in '.idea/modules.xml' so it points on project's root.Huffish
A
17

You can also use play to fix it

cd /path/to/project
play
[project] idea with-sources=yes

And now you can right click on Application and run Play2 application.

Anaplastic answered 2/7, 2014 at 23:31 Comment(3)
This worked for me & looks like a much cleaner solution. Thanks.Willpower
This worked for me, but instead of play I used sbt (since the play command is for older play versions)Tailback
I had to right click on the build.sbt and then Run Play 2. Then you can save the run configuration for future reference.Sheepshearing
P
10

Just ran into the same problem - my project is set up like so:

root/
  .idea/
  MainApp/ <-- this one is a Play 2.2.2 project
    .idea/
    apps/ <-- contains other Play2 projects

I was attempting to run the MainApp project and had the same problem.

If you notice in your run error: [info] Set current project to modules (in build file:/J:/DEV/TYPESAFE/reactive-maps/.idea/modules/)

states it is setting the project to modules. You want it to be reactive-maps.

Mine did the same - my quick solution:

-- find the file .idea/modules/reactive-maps.iml, move it to the root level reactive-maps/ directory.

-- Open the file, Ctrl-F Ctrl-R (find-and-replace)

-- Find: $MODULE_DIR$/../.. Replace with: $MODULE_DIR$/

Running the Play2 application again worked at this point.

The ideal solution would be importing it correctly (and I'm sure there is a way to do this), but this got my application running through IntelliJ quickly (although it will likely break on restart/SBT refresh).

Plumper answered 21/4, 2014 at 22:33 Comment(5)
From what I've noticed it happens when I import a project from existing module/sources (e.g. importing a project as an existing SBT module). Creating a new project from scratch always seems to workPlumper
:) Yep thats what I did.Jazzy
After applying your hack and after Idea restart it fails to open project. Idea complains about absent *.impl file in .idea/modules folderUlcerous
Interesting - I haven't seen that happen. I also re-structured my application so that I am no longer importing from existing sources/SBT module, which fixes the problem long-term.Plumper
Thank you. That worked for me. I also changed paths to modules' files in '.idea/modules.xml' so it points on project's root.Huffish

© 2022 - 2024 — McMap. All rights reserved.