0

I have the following Scala 2.10 script that works fine:

#!/bin/bash

classpath="${CLASSPATH}"
unset CLASSPATH

exec ${SCALA_HOME}/bin/scala -cp "${classpath}" "$0" "$@" 2>&1
!#

import stuff

But when CLASSPATH isn't unset, it fails with stuff like:

$ ./setter-for-catan.scala
./setter-for-catan.scala:12: error: not found: object play
import play.api.libs.json.JsArray
       ^

one error found

Why is this happening?

2 Answers 2

3

The scala script has a modest -debug option.

Use -Ylog-classpath to see what the compiler is using.

Use -nc to say "no compile server daemon".

Use fsc -shutdown to start over.

Package changes are anathema, so unexpected dirs in the path with package names, or old package objects, etc, cause inexplicable build problems.

Use PathResolver to dump what classpath it sees.

An empty directory with your package name can interfere with package discovery.

${SCALA_HOME}/bin/scala -cp "${classpath}" scala.tools.util.PathResolver
${SCALA_HOME}/bin/scala -cp "${classpath}" scala.tools.util.PathResolver some-args

You'll see something like:

apm@mara:~/tmp/scripts$ ./foo.sh
object Environment {
  scalaHome          = /media/Software/scala-2.10.1 (useJavaClassPath = true)
  javaBootClassPath  = <1122 chars>
  javaExtDirs        = 
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext
/usr/java/packages/lib/ext
  javaUserClassPath  = ""
  scalaExtDirs       = 
}
object Defaults {
  scalaHome            = /media/Software/scala-2.10.1
  javaBootClassPath    = 
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/resources.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/sunrsasign.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jsse.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jce.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/charsets.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/netx.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/plugin.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rhino.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jfr.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/classes
/media/Software/scala-2.10.1/lib/akka-actors.jar
/media/Software/scala-2.10.1/lib/jline.jar
/media/Software/scala-2.10.1/lib/scala-actors.jar
/media/Software/scala-2.10.1/lib/scala-actors-migration.jar
/media/Software/scala-2.10.1/lib/scala-compiler.jar
/media/Software/scala-2.10.1/lib/scala-library.jar
/media/Software/scala-2.10.1/lib/scala-partest.jar
/media/Software/scala-2.10.1/lib/scalap.jar
/media/Software/scala-2.10.1/lib/scala-reflect.jar
/media/Software/scala-2.10.1/lib/scala-swing.jar
/media/Software/scala-2.10.1/lib/typesafe-config.jar
  scalaLibDirFound     = Some(/media/Software/scala-2.10.1/lib)
  scalaLibFound        = /media/Software/scala-2.10.1/lib/scala-library.jar
  scalaBootClassPath   = 
  scalaPluginPath      = /media/Software/scala-2.10.1/misc/scala-devel/plugins
}
 COMMAND: 'scala some-args'
RESIDUAL: 'scala some-args'
Sign up to request clarification or add additional context in comments.

3 Comments

I added a call to PathResolver -debug before and after the unset CLASSPATH. There's absolutely no difference between the two.
@NoelYap Also try scala -nc -Ylog-classpath, where -nc ignores the external compiler; or fsc -shutdown. Maybe you're just dealing with compile state, since it says "object play" (not value play).
-nc worked. Then I removed it and the script still worked. Perhaps -nc reset whatever funky state the daemon was in?
2

There may be some funky state leftover from the compiler daemon. Try fsc -shutdown or scala -nc to reset the daemon.

3 Comments

What? I answered your question and you didn't bestow the green check? Although I find scala tooling intrinsically interesting, this situation says to me, "I don't need your help."
@som-snytt, PathResolver did NOT resolve the problem. Copy the answer I posted here and I'll delete mine and check yours (if the system still allows me to do so). You'll also note that I DID check your comment that led to my answer and I specifically asked that you create your own answer. I waited for such an answer from you but never saw one (instead you commented 'So happy for you') so I created my own. I'm grateful for your help and would gladly give you the credit for it.
@som-snytt, BTW, I tried tagging you in my comments, but SO seems to wipe out the tags if it's directed towards the answer owner.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.