Running a Scala Script with external dependencies

后端 未结 2 1996
春和景丽
春和景丽 2021-02-04 19:31

I have the following jars under /Users/joe/.scala/lib:

commons-codec-1.4.jar       
httpclient-4.1.1.jar        
httpcore-4.1.jar
commons-logging-1.1.1.jar   
ht         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-04 20:28

    I'm not going to answer your question, but you might be interested in this.

    Suppose you download and install SBT (version 0.10.0 or higher), and create a shell script called "scalas":

    java -Dsbt.main.class=sbt.ScriptMain \
         -Dsbt.boot.directory=/home/user/.sbt/boot \
         -jar sbt-launch.jar "$@"
    

    And then you write your script like this:

    #!/usr/bin/env scalas
    !#
    
    /***
    scalaVersion := "2.9.1"
    
    libraryDependencies ++= Seq(
      "commons-codec" % "commons-codec" % "1.4", 
      "org.apache.httpcomponents" % "httpclient" % "4.1.1",
      "org.apache.httpcomponents" % "httpcore" % "4.1",
      "commons-logging" % "commons-logging" % "1.1.1",
      "org.apache.httpcomponents" % "httpclient-cache" % "4.1.1", 
      "org.apache.httpcomponents" % "httpmime" % "4.1.1"
    )
    */
    
    println(new org.apache.http.client.DefaultHttpClient())
    

提交回复
热议问题