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

老子叫甜甜 提交于 2019-12-10 22:41:52

问题


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.databinder.net/Try+Dispatch.html

Thanks!


回答1:


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.




回答2:


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!)


来源:https://stackoverflow.com/questions/6200422/how-do-i-set-up-databinder-dispatch-to-use-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!