2016-09-16 265 views
0

我是新來斯卡拉時蔭試圖執行SBT更新我得到Scala構建失敗?

[error] /home/workspace/Scala/SparkTwitterStreaming/project/project/build.scala:1: expected class or object definition 
[error] name := "SparkTwitterStreaming" 
[error]^
[error] /home/workspace/Scala/SparkTwitterStreaming/project/project/build.scala:2: expected class or object definition 
[error] version := "1.0" 
[error]^
[error] /home/workspace/Scala/SparkTwitterStreaming/project/project/build.scala:3: expected class or object definition 
[error] scalaVersion := "2.11.6" 
[error]^
[error] /home/workspace/Scala/SparkTwitterStreaming/project/project/build.scala:5: expected class or object definition 
[error] libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "1.6.2" 
[error]^
[error] /home/workspace/Scala/SparkTwitterStreaming/project/project/build.scala:6: expected class or object definition 
[error] libraryDependencies += "com.typesafe" % "config" % "1.3.0" 
[error]^
[error] 5 errors found 

build.scala/build.sbt

name := "SparkTwitterStreaming" 

version := "1.0" 

scalaVersion := "2.11.6" 

libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "1.6.2" 

libraryDependencies += "com.typesafe" % "config" % "1.3.0" 
+0

什麼是你的'build.scala' /'build.sbt'是什麼樣子?你在哪個目錄下運行'sbt update'命令? –

+0

'name:=「SparkTwitterStreaming」 version:=「1.0」 scalaVersion:=「2.11.6」 libraryDependencies + =「org.apache.spark」%「spark-core_2.11」%「1.6.2」。 這是什麼?它具有bin,src,項目的文件夾SourceFolder:SparkTwitterStreaming – Anji

+0

這是什麼?它是'build.sbt'嗎?或'build.scala'?它位於什麼目錄?什麼是你的sbt項目的直接結構?你從哪裏調用sbt?請包括你的問題中的所有內容。 –

回答

1

看起來你是在混淆.scala.sbt文件。 SBT允許以兩種不同的方式定義構建。 .scala文件是正常的Scala文件,所以它們不能在頂層有代碼(並且在SBT中有name := "SparkTwitterStreaming"等等,只是Scala代碼),它必須位於trait/class/object中。 SBT本身負責以這種方式包裝.sbt文件。

SparkTwitterStreaming/project/project/build.scala看起來也錯了:有案件在SBT時,你會使用一個文件project/project下,但是這是不是其中之一。你可能想把這個文件移動到SparkTwitterStreaming/build.sbt

+0

感謝它的工作 – Anji

2

所以基本上...有效最小SBT項目有像下面的結構,

YourProject 
├── build.sbt 
└── src 
    └── main 
     └── scala 
      └── Main.scala 

,有點更詳細的項目會是這樣,

SparkTwitterStreaming 
├── build.sbt 
├── project 
│ ├── build.properties 
│   └── plugins.sbt 
└── src 
    └── main 
     └── scala 
      └── YouCode.scala 

和最小build.sbt外觀like,

name := "SparkTwitterStreaming" 

version := "1.0" 

scalaVersion := "2.11.6" 

libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "1.6.2" 

libraryDependencies += "com.typesafe" % "config" % "1.3.0" 

現在有些人喜歡用build.scala而不是build.sbt,在這種情況下,此build.scala應位於SparkTwitterStreaming/project目錄內。

SparkTwitterStreaming 
├── project 
│ ├── build.properties 
│ ├── plugins.sbt 
│ └── build.scala 
└── src 
    └── main 
     └── scala 
      └── YouCode.scala 

而且,上面build.sbt,相當於build.scala的樣子,

import sbt._ 
import Keys._ 

object MyBuild extends Build { // <--- here MyBuild can be renamed to anything 
    // if you needed extra resolvers 
    val pResolvers = Seq(
    "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots" 
) 

    val pDependencies = Seq(
    "org.apache.spark" % "spark-core_2.11" % "1.6.2", 
    "com.typesafe" % "config" % "1.3.0" 
) 

    val pBuildSettings = Seq (
    name := "SparkTwitterStreaming", 
    version := "1.0", 
    scalaVersion := "2.11.6", 
    resolvers ++= pResolvers, 
    libraryDependencies ++= pDependencies 
) 

    lazy val root = project.in(file(".")).settings(pBuildSettings) 
} 
+0

感謝您的信息 – Anji