scala之如何在 SBT 中编写 "import scala.io.Source", "import java.io"库

zhujiabin 阅读:154 2025-06-02 22:19:02 评论:0

我正在使用 SBT 编译 Scala 程序,但它给了我以下“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 格式如下:

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

任何人都可以帮助我如何在 SBT 中指定“import scala.io.Source”、“import java.io”。

请您参考如下方法:

需要区分库依赖项和包导入:库依赖项通过构建系统(如 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" 
) 

我们可以开发一个scala程序,它可以使用来自typesafe的配置库和来自scalaj的http库

示例.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 
} 


标签:java
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号