1

我正在使用最新版本的 Play 框架(即 2.2 版)开发一个项目,我想在类路径中包含 Twitter4j 库,以便将我的 Web 应用程序与 twitter 服务集成。实现这一目标的最佳方法是什么?

4

2 回答 2

2

playframework 使用 sbt 来管理依赖关系。只需在 build.sbt 文件中添加 twitter4j 依赖项,它就会被下载并添加到类路径中。

在 build.sbt 中添加依赖项,如下所示

  libraryDependencies += "org.twitter4j" % "twitter4j-core" % "2.1.4"

请看下面的链接

http://www.playframework.com/documentation/2.2.0/SBTDependencies

于 2013-09-28T12:39:18.390 回答
1

There are two approaches:

  1. Create a lib/ folder inside your Play application and drop your jar files into that. SBT (the build tool used by Play) will automatically take care of adding the jars to the classpath.

  2. Tell SBT to fetch the jar file for you. Add the following lines to your project/Build.scala:

val twitter4j       = "org.twitter4j" % "twitter4j-core" % "3.0"
resolvers += "twitter4j-repo" at "http://twitter4j.org/maven2"

Then update appDependencies to look like below:

val appDependencies = Seq(
    ...
    twitter4j
)

Next time you run Play or issue reload at the Play prompt, SBT will handle the classpath for you.

于 2013-09-28T12:43:13.127 回答