user972946
user972946

Reputation:

Scala REPL only runs as root user, gives error when run as non-root

I'm running 64-bit OpenSUSE 12.1, today I downloaded the latest Scala 2.9.2 from the official website, after unpacking the tgz and go to scala-2.9.2/bin directory, I executed "scala" and got this error message:

[init] error: error while loading <root>, error in opening zip file

Failed to initialize compiler: object scala not found.
** Note that as of 2.8 scala does not assume use of the java classpath.
** For the old behavior pass -usejavacp to scala, or if using a Settings
** object programatically, settings.usejavacp.value = true.

I attempted to run scala -usejavacp but it doesn't help. I've been using Scala a lot in many other distros and have never got this error before.

My OpenSUSE installation has OpenJDK 6 installed.

Please suggest your opinions, thank you!

I have made the following attempts to solve the problem:

  1. Install Oracle JDK 1.7 and run scala, confirmed that scala REPL reports running in hotspot JVM 1.7, same error occurs.
  2. Installed sbt and run "console" from sbt, same error occurs.
  3. strace and diff the output between sudo scala and scala as normal user, there is no difference except the error message above.
  4. scala -Ylog-classpath as su and normal user, then diff the output, same as above.
  5. disabled AppArmor and tried again, same error message.
  6. Download other scala versions (all of 2.9x, and 2.10 milestone 4), all of their REPL give the same error message.
  7. Made sure fsc is not running before scala REPL runs
  8. Made sure that the hostname is resolvable

well this is a really interesting problem, I'll definitely post a solution if I can luckily find it.

Thanks a lot for your help!

Last edit: Thanks for everyone here and on reddit (http://www.reddit.com/r/scala/comments/w5s0m/please_help_scala_only_runs_as_root_user_gives/) who offered very valuable suggestions to help me figure out this very strange issue. See my answer below for the solution.

Upvotes: 1

Views: 3186

Answers (4)

user3338799
user3338799

Reputation: 11

This is most probably caused by jdk-xxx/jre/lib/ext containing jars that is not readable. Please look for file starting with "."jar and "._jar" and remove them.

Upvotes: 0

user972946
user972946

Reputation:

I have just found out the reason:

A closer examination of the output of "strace -f scala" as normal user yields an interesting output:

[pid 11919] open("/usr/lib64/jvm/java-1.6.0-openjdk-1.6.0/jre/lib/ext/gnome-java-bridge.jar", O_RDONLY) = -1 EACCES (Permission denied)

Soon follow that, is the system call to inform user that scala REPL failed to initialize:

[pid 11919] write(1, "\nFailed to initialize compiler: "..., 260

The gnome-java-bridge.jar has permission 400, I changed it to 444 and problem is solved!

The permission issue seems to have been listed as OpenSUSE bug: http://lists.opensuse.org/opensuse-bugs/2012-07/msg00920.html

Upvotes: 1

Daniel C. Sobral
Daniel C. Sobral

Reputation: 297285

It looks like it's not being able to open `scala-library.jar´, or one of the other jar files required for REPL.

You did not say whether scalac works or not. That might give a clue.

At any rate, I'd make sure all of the jar files are a+r, and the directory they are in, as well as all other parent directories, are a+rx.

Upvotes: 0

xiefei
xiefei

Reputation: 6609

Do not put sbt-launch.jar in your $SCALA_HOME/lib directory, your project's lib directory, or anywhere it will be put on a classpath.

Upvotes: 1

Related Questions