Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play2 and Intellij no main class detected

I am trying to develop a play framework application within a sbt sub-project. The directory tree looks like this:

- main-project
|--sub-project
| |--app
| |--conf
| |--logs
| |--public
| |--test
|--project
|--build.sbt

If I try to run the play application using sbt shell with the following command

sub-project/run

Play starts correctly. However, if I try to run it with the IntelliJ Run Configuration, I get the error java.lang.RuntimeException: No main class detected.

Follows the first lines of log and the command launched by IJ:

/usr/java/jdk1.8.0_111/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:41258,suspend=y,server=n -Dfile.encoding=UTF8 -Djline.terminal=none -Dsbt.log.noformat=true -Dsbt.global.base=/tmp/sbt-global-pluginstub -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M -javaagent:/home/myusername/Programmi/idea-IU-173.3727.127/lib/rt/debugger-agent.jar=/tmp/capture.props -classpath /home/myusername/.IntelliJIdea2017.3/config/plugins/Scala/launcher/sbt-launch.jar:/home/myusername/Programmi/idea-IU-173.3727.127/lib/idea_rt.jar xsbt.boot.Boot "project sub-project" run
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256M; support was removed in 8.0
Connected to the target VM, address: '127.0.0.1:41258', transport: 'socket'
[warn] No sbt.version set in project/build.properties, base directory: /home/luca/IdeaProjects/main-project/sub-project
[info] Set current project to sub-project (in build file:/home/myusername/IdeaProjects/main-project/sub-project/)
[info] Updating {file:/home/myusername/IdeaProjects/main-project/sub-project/}sub-project...
[info] Done updating.
[error] java.lang.RuntimeException: No main class detected.

It looks like the sbt command is different than expected (sbt project sub-project run insted of sbt sub-project/run)

Anyone has ever configured IntelliJ to debug a play application with the launch tool? Thanks

like image 730
Luca Avatar asked Nov 07 '22 09:11

Luca


1 Answers

@Luca: It is because of plugin version conflict between scala plugin sbt version ,activator and intellij idea.New Intellij is trying to ignore the $PROJECT_DIR files and other flougins are putting the conf files there.

Workaround: Put this in your play2_project_settings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="Play2ExcludedModulesSettings">
    <option name="INFO">
      <map>
        <entry key="api">
          <value>
            <ProjectSettingsEntry>
              <option name="confDir" value="$PROJECT_DIR$/api/app" />
              <option name="templateImports">
                <list>
                  <option value="_root_.play.twirl.api.TwirlFeatureImports._" />
                  <option value="_root_.play.twirl.api.TwirlHelperImports._" />
                  <option value="_root_.play.twirl.api.Html" />
                  <option value="_root_.play.twirl.api.JavaScript" />
                  <option value="_root_.play.twirl.api.Txt" />
                  <option value="_root_.play.twirl.api.Xml" />
                  <option value="models._" />
                  <option value="controllers._" />
                  <option value="play.api.i18n._" />
                  <option value="views.xml._" />
                  <option value="play.api.templates.PlayMagic._" />
                  <option value="play.api.mvc._" />
                  <option value="play.api.data._" />
                </list>
              </option>
              <option name="routesImports">
                <list>
                  <option value="controllers.Assets.Asset" />
                </list>
              </option>
              <option name="uri" value="$PROJECT_DIR$/../../../../<custom-project-path>" />
            </ProjectSettingsEntry>
          </value>
        </entry>
        <entry key="chargeback-api">
          <value>
            <ProjectSettingsEntry>
              <option name="playDistrPath" value="$USER_HOME$/.coursier/cache/v1/https/repo1.maven.org/maven2/com/typesafe/play/play_2.12/2.6.11/play_2.12-2.6.11.jar" />
            </ProjectSettingsEntry>
          </value>
        </entry>
      </map>
    </option>
  </component>
</project>

Filepath

In custom-project-path put the absolute path of your project directory it will work like a charm!!

like image 185
frostcs Avatar answered Nov 17 '22 23:11

frostcs