开发者

How do I set up databinder dispatch to use in Eclipse?

I want to write some simple HTTP requests in Scala, but the Databinder Dispatch library only has instructions for sbt. As I'm a relative Eclipse newbie, can someone provide instructions on how I use it in my Scala project in Eclipse? I'm using Scala 2.9.0final. If it's incompatible with Dispatch, is there an alternative HTTP request library?

http://dispatch.databi开发者_JS百科nder.net/Try+Dispatch.html

Thanks!


The page you have linked to has instructions for trying out Dispatch using the sbt console. It is much easier to just do that on the command line, although if you are convinced to do this with Eclipse you can read your integration options.

If you want to set up a project and write some code that can be compiled that uses Dispatch, you should follow this guide.

Which shows you how to pull in dispatch as a dependency with either Maven or sbt. The main thing is that you want the dispatch + dependencies jars on your project classpath in Eclipse before you can start playing with it - sbt makes this easy in Scala and Maven for Java. So you should look around for how to do that in Eclipse to see your options.


Dispath is build on top of Apache HttpClient which is pure Java library (so can be used from Scala). But if you want to use Dispatch, you can:

  1. Git clone the example
  2. Install sbt
  3. Run sbt update
  4. Look into lib_managed/scala_${version}/compile dir
  5. Write a sample scala script Script.scala:

    import dispatch._
    val h = new Http
    val req = url("http://www.scala-lang.org/")
    val handler = req >>> System.out
    h(handler)
    h(url("http://www.scala-lang.org/") >>> System.out)
    
  6. Run a script with proper class path. On linux you can do

    scala -cp `echo lib_managed/scala_${version}/compile/*.jar | sed 's/ /:/g'` Script.scala
    
  7. Enjoy!)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜