error starting 'sbt' inside project direct

2019-08-01 22:26发布

问题:

I am learning functional programming on Coursera with Scala. To attempt an assignment, I need to start 'sbt' in a project directory. I am following the instructions here: https://class.coursera.org/progfun-004/assignment/view?assignment_id=2

This is the error I got. I am sure that there's a build.sbt file and src folder within the project directory, but somehow sbt fails on me. Any ideas?

alex@alex-K46CM:~/progfun-assignments/example  
$ sbt
[info] Loading project definition from /home/alex/progfun-assignments/example/project/project
[info] Loading project definition from /home/alex/progfun-assignments/example/project
[info] Compiling 8 Scala sources to /home/alex/progfun-assignments/example/project/target/scala-2.9.2/sbt-0.12/classes...
[error] error while loading <root>, zip file is empty
scala.tools.nsc.MissingRequirementError: object scala not found.
    at scala.tools.nsc.symtab.Definitions$definitions$.getModuleOrClass(Definitions.scala:655)
    at scala.tools.nsc.symtab.Definitions$definitions$.getModule(Definitions.scala:605)
    at scala.tools.nsc.symtab.Definitions$definitions$.ScalaPackage(Definitions.scala:145)
    at scala.tools.nsc.symtab.Definitions$definitions$.ScalaPackageClass(Definitions.scala:146)
    at scala.tools.nsc.symtab.Definitions$definitions$.AnyClass(Definitions.scala:176)
    at scala.tools.nsc.symtab.Definitions$definitions$.init(Definitions.scala:814)
    at scala.tools.nsc.Global$Run.<init>(Global.scala:697)
    at xsbt.CachedCompiler0.run(CompilerInterface.scala:86)
    at xsbt.CachedCompiler0.liftedTree1$1(CompilerInterface.scala:72)
    at xsbt.CachedCompiler0.run(CompilerInterface.scala:72)
    at xsbt.CompilerInterface.run(CompilerInterface.scala:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:73)
    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:35)
    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:29)
    at sbt.compiler.AggressiveCompile$$anonfun$4$$anonfun$compileScala$1$1.apply$mcV$sp(AggressiveCompile.scala:71)
    at sbt.compiler.AggressiveCompile$$anonfun$4$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:71)
    at sbt.compiler.AggressiveCompile$$anonfun$4$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:71)
    at sbt.compiler.AggressiveCompile.sbt$compiler$AggressiveCompile$$timed(AggressiveCompile.scala:101)
    at sbt.compiler.AggressiveCompile$$anonfun$4.compileScala$1(AggressiveCompile.scala:70)
    at sbt.compiler.AggressiveCompile$$anonfun$4.apply(AggressiveCompile.scala:88)
    at sbt.compiler.AggressiveCompile$$anonfun$4.apply(AggressiveCompile.scala:60)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:24)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:22)
    at sbt.inc.Incremental$.cycle(Incremental.scala:52)
    at sbt.inc.Incremental$.compile(Incremental.scala:29)
    at sbt.inc.IncrementalCompile$.apply(Compile.scala:20)
    at sbt.compiler.AggressiveCompile.compile2(AggressiveCompile.scala:96)
    at sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:44)
    at sbt.compiler.AggressiveCompile.apply(AggressiveCompile.scala:31)
    at sbt.Compiler$.apply(Compiler.scala:79)
    at sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:574)
    at sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:574)
    at sbt.Scoped$$anonfun$hf2$1.apply(Structure.scala:578)
    at sbt.Scoped$$anonfun$hf2$1.apply(Structure.scala:578)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:49)
    at sbt.Scoped$Reduced$$anonfun$combine$1$$anonfun$apply$12.apply(Structure.scala:311)
    at sbt.Scoped$Reduced$$anonfun$combine$1$$anonfun$apply$12.apply(Structure.scala:311)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:41)
    at sbt.std.Transform$$anon$5.work(System.scala:71)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:232)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:232)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:238)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:232)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:232)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
[error] (compile:compile) scala.tools.nsc.MissingRequirementError: object scala not found.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q

回答1:

try to remove your local ivy directory ~/.ivy2/, you may have some broken jars here. also check your environment variables related to sbt and scala. you can check whether it's your project problem or not by running sbt outside of sbt project, if error still appears, than it's sbt installation or environment problem



标签: scala sbt