繁体   English   中英

添加lift-json作为Play 2.0项目的构建依赖项

[英]Add lift-json as build dependency for Play 2.0 project

我是Scala和SBT的新手,我正在试图弄清楚如何在我的Play 2.0项目中添加lift-json作为构建依赖项。 lift-json文档说:

Add dependency to your project description:
val lift_json = "net.liftweb" %% "lift-json" % "XXX"

我甚至不确定“项目描述”实际存储在哪里,但我找到了一个具有以下内容的Build.scala:

import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

    val appName         = "test"
    val appVersion      = "1.0"

    val appDependencies = Seq(
      // Add your project dependencies here,
      "net.liftweb" %% "lift-json" % "2.9.1"
    )

    val main = PlayProject(appName, appVersion, appDependencies).settings(defaultScalaSettings:_*).settings(
      // Add your own project settings here      
    )

}

你可以看到我为net.liftweb添加的行。 不幸的是,这似乎是错误的地方,或错误的内容,因为我得到以下构建错误:

[info] Updating {file:/D:/play/test/}test...
[warn]  module not found: net.liftweb#lift-json_2.9.1;2.9.1
[warn] ==== local: tried
[warn]   D:\play\play-2.0-beta\framework\..\repository/local/net.liftweb/lift-json_2.9.1/2.9.1/ivys/ivy.xml
[warn]   -- artifact net.liftweb#lift-json_2.9.1;2.9.1!lift-json_2.9.1.jar:
[warn]   D:\play\play-2.0-beta\framework\..\repository/local/net.liftweb/lift-json_2.9.1/2.9.1/jars/lift-json_2.9.1.jar
[warn] ==== Play Repository: tried
[warn]   http://download.playframework.org/ivy-releases/net.liftweb/lift-json_2.9.1/2.9.1/ivys/ivy.xml
[warn]   -- artifact net.liftweb#lift-json_2.9.1;2.9.1!lift-json_2.9.1.jar:
[warn]   http://download.playframework.org/ivy-releases/net.liftweb/lift-json_2.9.1/2.9.1/jars/lift-json_2.9.1.jar
[warn] ==== Typesafe Repository: tried
[warn]   http://repo.typesafe.com/typesafe/releases/net/liftweb/lift-json_2.9.1/2.9.1/lift-json_2.9.1-2.9.1.pom
[warn]   -- artifact net.liftweb#lift-json_2.9.1;2.9.1!lift-json_2.9.1.jar:
[warn]   http://repo.typesafe.com/typesafe/releases/net/liftweb/lift-json_2.9.1/2.9.1/lift-json_2.9.1-2.9.1.jar
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/net/liftweb/lift-json_2.9.1/2.9.1/lift-json_2.9.1-2.9.1.pom
[warn]   -- artifact net.liftweb#lift-json_2.9.1;2.9.1!lift-json_2.9.1.jar:
[warn]   http://repo1.maven.org/maven2/net/liftweb/lift-json_2.9.1/2.9.1/lift-json_2.9.1-2.9.1.jar
[warn] ==== Scala-Tools Maven2 Repository: tried
[warn]   http://scala-tools.org/repo-releases/net/liftweb/lift-json_2.9.1/2.9.1/lift-json_2.9.1-2.9.1.pom
[warn]   -- artifact net.liftweb#lift-json_2.9.1;2.9.1!lift-json_2.9.1.jar:
[warn]   http://scala-tools.org/repo-releases/net/liftweb/lift-json_2.9.1/2.9.1/lift-json_2.9.1-2.9.1.jar
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: net.liftweb#lift-json_2.9.1;2.9.1: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[error] {file:/D:/play/test/}test/*:update: sbt.ResolveException: unresolved dependency: net.liftweb#lift-json_2.9.1;2.9
.1: not found
[error] application -

! @68mcpckf2 - Internal server error, for request [GET /] ->

play.api.UnexpectedException: Unexpected exception [ResolveException: unresolved dependency: net.liftweb#lift-json_2.9.1
;2.9.1: not found]
        at sbt.PlayProject$$anon$1$$anonfun$reload$1$$anonfun$apply$36.apply(SbtPlugin.scala:518) ~[play_2.9.1.jar:na]
        at sbt.PlayProject$$anon$1$$anonfun$reload$1$$anonfun$apply$36.apply(SbtPlugin.scala:511) ~[play_2.9.1.jar:na]
        at scala.Option.map(Option.scala:133) [scala-library.jar:na]
        at sbt.PlayProject$$anon$1$$anonfun$reload$1.apply(SbtPlugin.scala:511) ~[play_2.9.1.jar:na]
        at sbt.PlayProject$$anon$1$$anonfun$reload$1.apply(SbtPlugin.scala:510) ~[play_2.9.1.jar:na]
        at scala.Either$LeftProjection.map(Either.scala:183) ~[scala-library.jar:na]
Caused by: sbt.ResolveException: unresolved dependency: net.liftweb#lift-json_2.9.1;2.9.1: not found
        at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:216) ~[ivy_2.9.1-0.11.0.jar:na]
        at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:130) ~[ivy_2.9.1-0.11.0.jar:na]
        at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:129) ~[ivy_2.9.1-0.11.0.jar:na]
        at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:110) ~[ivy_2.9.1-0.11.0.jar:na]
        at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:110) ~[ivy_2.9.1-0.11.0.jar:na]
        at sbt.IvySbt$$anonfun$withIvy$1.apply(Ivy.scala:98) ~[ivy_2.9.1-0.11.0.jar:na]

我有一个Lift源代码的副本,但我不知道放在哪里。 而且我很确定我把这种依赖放在了错误的地方。 有人可以指点我正确的方向吗?

你真的很接近 - 唯一的问题是你的lift-json版本号错了。

当你进入Scala + SBT世界时,有一件事可能会令人困惑的是,包是为特定版本的Scala构建的。 目前版本的lift-json是2.4-M5。 尽管如此,你可能已经看到了像“lift-json_2.9.1”这样的软件包名称。 这里的2.9.1指的是构建包的Scala版本。 当您使用引用的%%语法时,SBT会自动将您正在使用的Scala版本添加到包名称中; 所以你需要指定的唯一版本号是lift-json。

因此你需要

"net.liftweb" %% "lift-json" % "2.4-M5"

这只是简写

"net.liftweb" % "lift-json_2.9.1" % "2.4-M5"

(注意一个%vs两个%%)。

SBT入门指南非常有帮助; 一开始可能会有点吓人,想弄清楚它是如何工作的(这与Ant或Maven的方法完全不同),但是如果你要使用它,那么值得一试。

您根本不需要Lift源代码,因为SBT将下载您需要的所有内容 - 包括源包,因此您的IDE或调试器可以导航到它。

大卫的答案是正确的,然而,我仍然发现很难找到正确的版本。 (2.4-M5同时过时)

您应该看看最近的版本:

http://repo1.maven.org/maven2/net/liftweb/

寻找lift-json和用于获取正确目录的scala版本,对我而言:

http://repo1.maven.org/maven2/net/liftweb/lift-json_2.11/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM