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:
- Git clone the example
- Install sbt
- Run
sbt update
- Look into
lib_managed/scala_${version}/compile
dir 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)
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
- Enjoy!)
精彩评论