Play2和Intellij没有检测到主类

时间:2018-03-23 18:01:57

标签: intellij-idea playframework sbt

我正在尝试在sbt子项目中开发一个play框架应用程序。目录树如下所示:

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

如果我尝试使用带有以下命令的sbt shell运行播放应用程序

sub-project/run

播放正确开始。 但是,如果我尝试使用IntelliJ运行配置运行它,我会收到错误java.lang.RuntimeException: No main class detected.

遵循日志的第一行和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.

看起来sbt命令与预期不同(sbt project sub-project run sbt sub-project/run {/ p>}

有没有人配置IntelliJ来使用启动工具调试播放应用程序? 感谢

3 个答案:

答案 0 :(得分:1)

@Luca:这是因为Scala插件sbt版本,激活器和intellij想法之间存在插件版本冲突。新的Intellij试图忽略$ PROJECT_DIR文件,而其他Fluugins则将conf文件放在那里。

解决方法: 将其放入您的 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

在custom-project-path中放入项目目录的绝对路径,它将像超级按钮一样工作!

答案 1 :(得分:0)

在我的项目中运行通常就足够了 - 但我试了一下,比如:

enter image description here

它有效。我的控制台看起来像:

/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:55426,suspend=y,server=n -Dconfig.file=server/conf/demo.conf -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -javaagent:/Users/pascal.mengelt/Library/Caches/IntelliJIdea2017.3/captureAgent/debugger-agent.jar=/private/var/folders/cj/t4h2s_g56w1b78ck_mp1c1w40000gp/T/capture.props -Dfile.encoding=UTF-8 -classpath "/Users/pascal.mengelt/Library/Application Support/IntelliJIdea2017.3/Scala/launcher/sbt-launch.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar" xsbt.boot.Boot server/run
objc[15772]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/bin/java (0x10d7794c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10e8b44e0). One of the two will be used. Which one is undefined.
Connected to the target VM, address: '127.0.0.1:55426', transport: 'socket'
[info] Loading settings from idea.sbt ...
...

您在此处找到的整个项目: scala-adapters

答案 2 :(得分:0)

以上两种方式均有效。

有关@frostcs答案的更多详细说明:

  1. 打开play2_project_settings.xml
  2. 找到以下关键行:

     <option name="uri" value="/E:/jc/code/lets-build-a-blockchain/stage1" />
    
  3. $PROJECT_DIR$/../../../../设置为uri的值。如下

     <option name="uri" value="$PROJECT_DIR$/../../../../E:/jc/code/lets-build-a-blockchain/stage1" />
    
  4. 它将像护身符一样工作!