开发者

Trying to run sbt on Ubuntu. (Error: java.lang.NoClassDefFoundError: scala/ScalaObject)

开发者 https://www.devze.com 2023-01-26 00:32 出处:网络
I\'ve tried installing sbt to start using Scala version 2.8 in Ubuntu. (I\'m currently using version 2.7.)

I've tried installing sbt to start using Scala version 2.8 in Ubuntu. (I'm currently using version 2.7.)

When I run sbt from the terminal I get the following output:

$ sbt
Project does not exist, create new project? (y/N/s) y
Name: HelloWorld
Organization: org
Versio开发者_Go百科n [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

Any ideas what I'm doing wrong?


This error happens when an incorrect Scala version is used. Since SBT manages Scala on its own, my suggestion is that you remove any Scala package you might have installed.


Try a restart sbt after deleting:

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

As described in sbt troubleshooting


Do you have set your $SCALA_HOME environment variable properly?

I saw the Conky GUI Ubuntu project having a similar issue (bottom of the page, not with sbt directly, but with Scala), and here is the script they are now using to make sure and set all Scala related variables:

(The all script is probably not relevant for your sbt script, but it gives you an idea about setting $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 $?
0

精彩评论

暂无评论...
验证码 换一张
取 消