2016-11-10 28 views
3

我正在使用SBT編譯Scala程序,但是它給我提供了以下「import scala.io.Source」錯誤,如何在SBT編寫「import scala.io.Source」,「import java.io」庫

sbt.ResolveException: unresolved dependency: org.scala#scala.io.Source_2.11;latest.integration: not found 
[error] unresolved dependency: org.java#java.io_2.11;latest.integration: not found 

我SBT格式如下 「導入java.io」:

name := "Simple Project" 

version := "1.0" 

scalaVersion := "2.11.7" 

libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-graphx" % "2.0.1", 
"org.scala" %% "scala.io.Source" % "latest.integration", 
"org.java" %% "java.io" % "latest.integration" 
) 

有人能幫助那我怎麼可以指定 「進口scala.io.Source」,「導入java.io 「在SBT中。

+0

'scala.io Scala程序。 Source'是一個不是SBT依賴的scala包。從sbt中刪除它。 'java.io'也一樣。 – maasg

+0

另請參閱:http://www.scala-sbt.org/0.13/docs/Getting-Started.html – maasg

回答

5

需要區分庫依賴和包導入:通過構建系統(如sbt或maven或grails等)管理庫依賴關係,並創建完整的庫(如日誌API,HTTP實現, ...)可用於正在構建的系統。

在程序層面,imports用於將庫的特定部分納入所開發代碼的範圍。

鑑於這種build.sbt

name := "examplebuild" 

version := "0.0.1" 

scalaVersion := "2.11.7" 

libraryDependencies ++= Seq(
    "com.typesafe" % "config" % "1.2.1", 
    "org.scalaj" % "scalaj-http_2.11" % "2.3.0" 
) 

我們能夠開發出可以使用配置庫的類型安全和HTTP庫從scalaj

Sample.scala

package com.example 

import scala.io.Source // from the Scala standard library 
import java.io._ // import all io package from the standard java library 

import com.typesafe.ConfigFactory // from the typesafe config library 
import scalaj.http._ // import all members of the scalaj.http package 

class Sample { 
    // code here 
}