Sbt找不到Java

时间:2017-11-11 10:26:58

标签: java scala parsing path sbt

当我尝试启动sbt时,收到以下消息:

~(501)$sbt
(standard_in) 1: parse error

No java installations was detected.
Please go to http://www.java.com/getjava/ and download

但是,已安装Java和Scala

~(508)$java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

这是Scala

~(503)$scala
Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 9.0.1).
Type in expressions for evaluation. Or try :help.

scala> 

你可以在路径中找到它们

Java路径

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/"     
export PATH=$PATH:"/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/"   

Sbt path

export SBT_HOME="/usr/local/Cellar/sbt/1.0.3/bin/" 
export PATH=$PATH:$SBT_HOME

和Scala路径

export SCALA_HOME="/usr/local/opt/scala/idea"
export PATH=$PATH:$SCALA_HOME/bin

我在Mac Os Sierra v10.12.6中运行所有这些 我会感激任何帮助。提前谢谢。

2 个答案:

答案 0 :(得分:2)

感谢您的回答,这对我帮助很大。

最重要的是修复了grep选项:

   #GREP_OPTIONS="--color=always";export GREP_OPTIONS
   #pay attention - don't use previous line or sbt for scala won't work,
   #this is the reason why to keep active the following line
   GREP_OPTIONS=""

另外,我正确地重写了路径和变量设置。在我从zip文件中设置sbt的全新安装的方式,所以我包含了一个特定的别名来覆盖以前的设置并在.bash_profile中启动它

### Java 
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home"
export PATH=$PATH:$JAVA_HOME/bin

### SBT
#alias is to force launch from fresh install from .zip file
alias sbt="~/sbt/bin/sbt"
export SBT_HOME="~/sbt"
export PATH=$PATH:$SBT_HOME/bin

答案 1 :(得分:1)

JAVA_HOMEPATH不应指向同一目录。 JAVA_HOME指向Java目录,PATH指向其bin子目录。 例如对我来说

$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
$ echo $PATH
...:/usr/lib/jvm/java-8-oracle/bin:...

另见

Why does sbt report "No java installations was detected" with $JAVA_HOME set?

No Java installation was detected while sbt update

https://apple.stackexchange.com/questions/163418/no-java-installations-was-detected-although-i-have-java

Installing Java on OS X 10.9 (Mavericks)