我尝试安装sbt
以开始在Ubuntu中使用Scala版本2.8。 (我目前正在使用2.7版本。)
当我从终端运行sbt
时,我得到以下输出:
$ sbt
Project does not exist, create new project? (y/N/s) y
Name: HelloWorld
Organization: org
Version [1.0]:
Scala version [2.7.7]:
sbt version [0.7.4]:
Getting Scala 2.7.7 ...
:: retrieving :: org.scala-tools.sbt#boot-scala
confs: [default]
2 artifacts copied, 0 already retrieved (6214kB/279ms)
java.lang.NoClassDefFoundError: scala/ScalaObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at xsbt.boot.Provider$.classMissing$1(Provider.scala:71)
at xsbt.boot.Provider$$anonfun$getMissing$1.apply(Provider.scala:72)
at xsbt.boot.Provider$$anonfun$getMissing$1.apply(Provider.scala:72)
at scala.List.filter(List.scala:859)
at xsbt.boot.Provider$.getMissing(Provider.scala:72)
at xsbt.boot.Provider$initialize.call(Provider.scala:45)
at xsbt.boot.Provider$initialize.call(Provider.scala:32)
at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:63)
at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:67)
at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:67)
at xsbt.boot.Using$.withResource(Using.scala:11)
at xsbt.boot.Using$.apply(Using.scala:10)
at xsbt.boot.Locks$GlobalLock.withFileLock(Locks.scala:67)
at xsbt.boot.Locks$GlobalLock.liftedTree1$1(Locks.scala:45)
at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:45)
at xsbt.boot.Locks$.apply(Locks.scala:31)
at xsbt.boot.Provider$class.$init$(Provider.scala:31)
at xsbt.boot.Launch$ScalaProvider.<init>(Launch.scala:80)
at xsbt.boot.Launch$$anonfun$1.apply(Launch.scala:72)
at xsbt.boot.Launch$$anonfun$1.apply(Launch.scala:72)
at xsbt.boot.Cache.newEntry(Cache.scala:17)
at xsbt.boot.Cache.getFromReference(Cache.scala:13)
at xsbt.boot.Cache.apply(Cache.scala:12)
at xsbt.boot.Launch.getScala(Launch.scala:73)
at xsbt.boot.Launch$.run(Launch.scala:48)
at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:42)
at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:42)
at xsbt.boot.Launch$.launch(Launch.scala:57)
at xsbt.boot.Launch$.explicit(Launch.scala:42)
at xsbt.boot.Launch$.initialized(Launch.scala:38)
at xsbt.boot.Launch$.parsed(Launch.scala:31)
at xsbt.boot.Launch$.configured(Launch.scala:21)
at xsbt.boot.Launch$.apply(Launch.scala:16)
at xsbt.boot.Launch$.apply(Launch.scala:13)
at xsbt.boot.Boot$.runImpl(Boot.scala:24)
at xsbt.boot.Boot$.run(Boot.scala:19)
at xsbt.boot.Boot$.main(Boot.scala:15)
at xsbt.boot.Boot.main(Boot.scala)
Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 62 more
Error during sbt execution: java.lang.NoClassDefFoundError: scala/ScalaObject
任何想法我做错了什么?
答案 0 :(得分:2)
使用不正确的Scala版本时会发生此错误。由于SBT自行管理Scala,我的建议是删除您可能安装的任何Scala软件包。
答案 1 :(得分:2)
删除后尝试重新启动sbt
:
~/.m2/repository
~/.ivy2/cache
project/boot
答案 2 :(得分:0)
您是否正确设置了$SCALA_HOME
环境变量?
我看到Conky GUI Ubuntu project having a similar issue(页面底部,不是直接使用sbt,而是使用Scala),这是他们现在用来确保和设置所有Scala相关变量的脚本:
(所有脚本可能与您的sbt脚本无关,但它可以让您了解如何设置$SCALA_HOME
)
#!/bin/bash
set -e
#-----------------------------------#
# Functions #
#-----------------------------------#
function copy_variables_file {
# Copying variables.xml to ~/.conkygui
if [ ! -d ~/.conkygui ]; then
mkdir -v ~/.conkygui
fi
cp -vu /usr/share/doc/conkygui/variables.xml ~/.conkygui
}
function get_scala_home {
# check if $SCALA_HOME is set
if [ -z $SCALA_HOME ]; then
# try to find it at common locations
dists=('Fedora' 'Ubuntu')
paths=('/usr/share/scala' '/usr/share/java')
for indx in 0 1
do
SCALA_HOME=${paths[$indx]}
if [ -d $SCALA_HOME ]; then
break
fi
SCALA_HOME=''
done
fi
# check if $SCALA_HOME could be found
if [ -z $SCALA_HOME ]; then
echo '$SCALA_HOME is not set'
exit 2
else
echo $SCALA_HOME
return 0
fi
}
function get_scala_library_path {
SCALA_HOME=$1
scala_library=$SCALA_HOME'/scala-library.jar'
if [ -f $scala_library ] ; then
echo $scala_library
return 0
fi
# try with lib folder
scala_library=$SCALA_HOME'/lib/scala-library.jar'
if [ -f $scala_library ] ; then
echo $scala_library
return 0
else
echo 'error: scala-library.jar could not be found';
exit 1
fi
}
function get_classpath {
SCALA_HOME=$1
# Except for Scala the required libraries come
# with Conky GUI and are located in the "lib" folder.
lib_folder='/usr/share/conkygui'
bsaf=$lib_folder'/lib/bsaf-1.9-RC3.jar'
vldocking=$lib_folder'/lib/vldocking-3.0.0.jar'
conkygui=$lib_folder'/conkygui.jar'
libs=$bsaf':'$vldocking':'$conkygui
scala_library=`get_scala_library_path $SCALA_HOME`
classpath=$libs':'$scala_library
echo $classpath
}
#-------------------------------#
# RUN #
#-------------------------------#
copy_variables_file
SCALA_HOME=`get_scala_home`
echo 'SCALA_HOME: '$SCALA_HOME
classpath=`get_classpath $SCALA_HOME`
echo 'CLASSPATH: '$classpath
# start Conky GUI
java -cp $classpath controllers.ConkyGUI
exit $?