我正在尝试在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命令与预期不同(qazxsw poi而不是qazxsw poi)
有没有人配置IntelliJ来使用启动工具调试播放应用程序?谢谢
@Luca:这是因为scala插件sbt版本,激活器和intellij idea之间的插件版本冲突。新Intellij试图忽略$ PROJECT_DIR文件,其他flougins将conf文件放在那里。
解决方法:将其放在play2_project_settings.xml中:
/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 ...
...
在自定义项目路径中,将项目目录的绝对路径设置为魅力!
以上两种方式都有效。
有关@frostcs答案的更详细说明:
<?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>
play2_project_settings.xml
前置为 <option name="uri" value="/E:/jc/code/lets-build-a-blockchain/stage1" />
值。如下
$PROJECT_DIR$/../../../../