在eclipse中播放2.1应用程序作为scala项目(而不是java项目)

时间:2014-02-17 19:02:37

标签: java scala sbt playframework-2.1

如何配置playframework-2.1应用程序build.scala文件以生成具有scalanature而非javanature的eclipse项目?

我找到了这段代码(https://github.com/playframework/playframework/blob/2.1.x/framework/src/sbt-plugin/src/main/scala/play/Project.scala

val mainLang = if (dependencies.contains(javaCore)) JAVA else SCALA

这表明如果我在依赖项中有javaCore,我将获得一个JAVA项目。 我试图删除javaCore上的依赖项,但我有编译错误。

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

我设法能够配置

的playframework项目
  • 使用java和scala源
  • 使用scala natures生成eclipse项目
  • 在eclipse中正确编译
  • 使用playframework-2.1.x

脚本如下

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {

    val appName         = "darzaar"
    val appVersion      = "1.0-SNAPSHOT"
    //play.Project.playScalaSettings - is available only in playframework-2.2.x
    val appDependencies = Seq(
      // added instead of javaCore
      "play"  %%  "play-java"     % "2.1.5",
      "be.objectify"  %%  "deadbolt-java"     % "2.1-RC2",
      "be.objectify"  %%  "deadbolt-scala"     % "2.1-RC2",
      // Comment this for local development of the Play Authentication core
      "com.feth"      %%  "play-authenticate" % "0.3.4-SNAPSHOT",
      "postgresql"    %   "postgresql"        % "9.1-901-1.jdbc4",
      //javaCore, - commented to keep SCALA nature in eclipse
      //javaJdbc,
      jdbc,
      javaEbean
    )

    import com.typesafe.sbteclipse.core.EclipsePlugin._ 

    val main = play.Project(appName, appVersion, appDependencies)
        //.settings(play.Project.playScalaSettings:_*)
        .settings(
      resolvers += Resolver.url("Objectify Play Repository (release)", url("http://schaloner.github.com/releases/"))(Resolver.ivyStylePatterns),
      resolvers += Resolver.url("Objectify Play Repository (snapshot)", url("http://schaloner.github.com/snapshots/"))(Resolver.ivyStylePatterns),

      resolvers += Resolver.url("play-easymail (release)", url("http://joscha.github.com/play-easymail/repo/releases/"))(Resolver.ivyStylePatterns),
      resolvers += Resolver.url("play-easymail (snapshot)", url("http://joscha.github.com/play-easymail/repo/snapshots/"))(Resolver.ivyStylePatterns),

      resolvers += Resolver.url("play-authenticate (release)", url("http://joscha.github.com/play-authenticate/repo/releases/"))(Resolver.ivyStylePatterns),
      resolvers += Resolver.url("play-authenticate (snapshot)", url("http://joscha.github.com/play-authenticate/repo/snapshots/"))(Resolver.ivyStylePatterns)

      // These keys wheren't used by sbt-eclipse when used in playframework
      //,EclipseKeys.projectFlavor := EclipseProjectFlavor.Scala
      //,PlayEclipse.mainLang := SCALA
    )
//  Uncomment this for local development of the Play Authenticate core:
//    .dependsOn(playAuthenticate).aggregate(playAuthenticate)

}

我还需要向某些模板添加以下导入,因为defaultScalaTemplatesImporthttps://github.com/playframework/playframework/blob/b4006e9dbecaca6f8257a209f7d0fdc6e0345b48/framework/src/sbt-plugin/src/main/scala/PlayKeys.scala上的defaultJavaTemplatesImport不同

@import play.mvc.Http.Context.Implicit._
@import scala.collection.JavaConversions._
@import scala.collection.JavaConverters._

答案 1 :(得分:0)

在plugins.sbt中添加以下Sbt eclipse插件

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.3.0")

在播放控制台中输入“eclipse”并按Enter键。

看看SBTEclipse plugin。我看到你已经在Play的最新版本。我建议你尝试一下类型安全的'激活器'。