代码之家  ›  专栏  ›  技术社区  ›  aioobe

尝试在Ubuntu上运行sbt。(错误:java.lang.NoClassDefFoundError:scala/ScalaObject)

  •  3
  • aioobe  · 技术社区  · 14 年前

    我试过安装 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
    

    你知道我做错了什么吗?

    3 回复  |  直到 14 年前
        1
  •  2
  •   Daniel C. Sobral    14 年前

    使用不正确的Scala版本时会发生此错误。既然SBT自己管理Scala,我的建议是 去除 任何你可能已经安装的Scala包。

        2
  •  2
  •   radke    14 年前

    尝试重新启动 sbt 删除后:

    1. ~/.m2/repository
    2. ~/.ivy2/cache
    3. project/boot

    如中所述 sbt troubleshooting

        3
  •  0
  •   VonC    14 年前

    你把你的 $SCALA_HOME 环境变量是否正确?

    我看到了 Conky GUI Ubuntu project having a similar issue (页面底部,不是直接使用sbt,而是使用Scala),下面是他们现在用来确保和设置所有Scala相关变量的脚本:

    (all脚本可能与sbt脚本无关,但它为您提供了有关设置的想法 $SCALA_主页 )

    #!/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 $?
    
    推荐文章