This page is no longer maintained — Please continue to the home page at www.scala-lang.org

How to track down "java.lang.NoClassDefFoundError: scala/ScalaObject" error

6 replies
Kenneth McDonald
Joined: 2009-01-11,
User offline. Last seen 42 years 45 weeks ago.

I'm experiencing this trying to run the maven test target, but a google search reveals it to be a fairly commonly encountered error. One cause seems to be that the scala library isn't on the classpath/in the list of dependencies, but as far as I can tell, maven has all the necessary info to find the scala 2.8.0 library. Any suggestions as to how to go about tracking down the actual source of this error? The stack trace quickly gets into class loaders, which is all black magic to me...

Thanks,
Ken

Lex
Joined: 2010-02-28,
User offline. Last seen 42 years 45 weeks ago.
Re: How to track down "java.lang.NoClassDefFoundError: scala/Sc
The only possible source of this error is when a classloader is unable to load the said class, which is a part of the scala library. So you are either missing the scala library on the classpath or the library jar is corrupt.

You can be missing the library when trying to execute the compiler (nothing gets compiled). Or you can be missing the library when trying to run your tests (tests compile but do not run). In the latter case specifying the scala library as a compile-time dependency may not be enough, and you will have to specify it as a runtime dependency for the tests.


On Thu, Sep 23, 2010 at 12:40 AM, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
I'm experiencing this trying to run the maven test target, but a google search reveals it to be a fairly commonly encountered error. One cause seems to be that the scala library isn't on the classpath/in the list of dependencies, but as far as I can tell, maven has all the necessary info to find the scala 2.8.0 library. Any suggestions as to how to go about tracking down the actual source of this error? The stack trace quickly gets into class loaders, which is all black magic to me...

Thanks,
Ken

Mikko Peltonen
Joined: 2010-05-05,
User offline. Last seen 42 years 45 weeks ago.
Re: How to track down "java.lang.NoClassDefFoundError: scala/Sc

What does "mvn -version" say?

-Mikko-

2010/9/23 Kenneth McDonald :
> I'm experiencing this trying to run the maven test target, but a google search reveals it to be a fairly commonly encountered error. One cause seems to be that the scala library isn't on the classpath/in the list of dependencies, but as far as I can tell, maven has all the necessary info to find the scala 2.8.0 library. Any suggestions as to how to go about tracking down the actual source of this error? The stack trace quickly gets into class loaders, which is all black magic to me...
>
> Thanks,
> Ken

Kenneth McDonald
Joined: 2009-01-11,
User offline. Last seen 42 years 45 weeks ago.
Re: How to track down "java.lang.NoClassDefFoundError: scala/Sc
Hi everyone, thanks for all the help.
First of all, here's the result of mvn -v. As far as I know this is an up to date version of maven.
Apache Maven 2.2.1 (r801777; 2009-08-06 14:16:01-0500)Java version: 1.6.0_20Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/HomeDefault locale: en_US, platform encoding: MacRomanOS name: "mac os x" version: "10.6.4" arch: "i386" Family: "mac"
Next, I've already deleted scala-lang (thanks to David Bernard for how to do this) and it's been reloaded, so I doubt it's a corruption problem there.
The compile phase does work. I have debug mode turned on for maven, and the relevant line on the console output is:
[DEBUG] cmd:  /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java -classpath /Users/Ken/.m2/repository/org/scala-lang/scala-library/2.8.0/scala-library-2.8.0.jar:/Users/Ken/.m2/repository/org/scala-lang/scala-compiler/2.8.0/scala-compiler-2.8.0.jar:/Users/Ken/.m2/repository/org/scala-tools/maven-scala-plugin/2.14.2-SNAPSHOT/maven-scala-plugin-2.14.2-SNAPSHOT.jar -Xbootclasspath/a:/Users/Ken/.m2/repository/org/scala-lang/scala-library/2.8.0/scala-library-2.8.0.jar org_scala_tools_maven_executions.MainWithArgsInFile scala.tools.nsc.Main /private/var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/scala-maven-6531627448163474925.args
So the library is included there.
When I try a test, I get a command of a very different nature:
Forking command line: /bin/sh -c cd /Users/Ken/mvn_projects/rex && /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java -jar /var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/surefirebooter7092588256684063981.jar /var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/surefire7499230852803569407tmp /var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/surefire6657987389890315523tmp
No explicit mention of the scala library. Does the test phase move that lib into one of the temp folders? That wouldn't make much sense, IMHO. But the scala lib is included as an unscoped dependency in my pom file:
      <dependency>        <groupId>org.scala-lang</groupId>        <artifactId>scala-library</artifactId>        <version>${scala.version}</version>      </dependency>
Since it's unscoped, I assumed it would apply to all of the maven phases. (I'm still very much learning maven on a "need to know" basis.")
I will read up on how to include this as a runtime dependency for the tests, but if any of the above strikes you as suspicious, please post.
Thanks,Ken

On Sep 23, 2010, at 2:26 AM, Lex wrote:
The only possible source of this error is when a classloader is unable to load the said class, which is a part of the scala library. So you are either missing the scala library on the classpath or the library jar is corrupt.

You can be missing the library when trying to execute the compiler (nothing gets compiled). Or you can be missing the library when trying to run your tests (tests compile but do not run). In the latter case specifying the scala library as a compile-time dependency may not be enough, and you will have to specify it as a runtime dependency for the tests.


On Thu, Sep 23, 2010 at 12:40 AM, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
I'm experiencing this trying to run the maven test target, but a google search reveals it to be a fairly commonly encountered error. One cause seems to be that the scala library isn't on the classpath/in the list of dependencies, but as far as I can tell, maven has all the necessary info to find the scala 2.8.0 library. Any suggestions as to how to go about tracking down the actual source of this error? The stack trace quickly gets into class loaders, which is all black magic to me...

Thanks,
Ken


Kenneth McDonald
Joined: 2009-01-11,
User offline. Last seen 42 years 45 weeks ago.
Re: How to track down "java.lang.NoClassDefFoundError: scala/Sc
Quick note: found this on the maven site:
  • compile
    This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects
So, in theory, the scala library should be available to the "test" phase of the lifecycle, if I'm not misreading this. Just to check I added in the dependency:
      <dependency>        <groupId>org.scala-lang</groupId>        <artifactId>scala-library</artifactId>        <version>${scala.version}</version>
   <scope>test</scope>
      </dependency>

and got the same error I've been getting, i.e. scala/ScalaObject unknown.
Thanks,Ken


On Sep 23, 2010, at 11:53 AM, Kenneth McDonald wrote:
Hi everyone, thanks for all the help.
First of all, here's the result of mvn -v. As far as I know this is an up to date version of maven.
Apache Maven 2.2.1 (r801777; 2009-08-06 14:16:01-0500)Java version: 1.6.0_20Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/HomeDefault locale: en_US, platform encoding: MacRomanOS name: "mac os x" version: "10.6.4" arch: "i386" Family: "mac"
Next, I've already deleted scala-lang (thanks to David Bernard for how to do this) and it's been reloaded, so I doubt it's a corruption problem there.
The compile phase does work. I have debug mode turned on for maven, and the relevant line on the console output is:
[DEBUG] cmd:  /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java -classpath /Users/Ken/.m2/repository/org/scala-lang/scala-library/2.8.0/scala-library-2.8.0.jar:/Users/Ken/.m2/repository/org/scala-lang/scala-compiler/2.8.0/scala-compiler-2.8.0.jar:/Users/Ken/.m2/repository/org/scala-tools/maven-scala-plugin/2.14.2-SNAPSHOT/maven-scala-plugin-2.14.2-SNAPSHOT.jar -Xbootclasspath/a:/Users/Ken/.m2/repository/org/scala-lang/scala-library/2.8.0/scala-library-2.8.0.jar org_scala_tools_maven_executions.MainWithArgsInFile scala.tools.nsc.Main /private/var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/scala-maven-6531627448163474925.args
So the library is included there.
When I try a test, I get a command of a very different nature:
Forking command line: /bin/sh -c cd /Users/Ken/mvn_projects/rex && /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java -jar /var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/surefirebooter7092588256684063981.jar /var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/surefire7499230852803569407tmp /var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/surefire6657987389890315523tmp
No explicit mention of the scala library. Does the test phase move that lib into one of the temp folders? That wouldn't make much sense, IMHO. But the scala lib is included as an unscoped dependency in my pom file:
      <dependency>        <groupId>org.scala-lang</groupId>        <artifactId>scala-library</artifactId>        <version>${scala.version}</version>      </dependency>
Since it's unscoped, I assumed it would apply to all of the maven phases. (I'm still very much learning maven on a "need to know" basis.")
I will read up on how to include this as a runtime dependency for the tests, but if any of the above strikes you as suspicious, please post.
Thanks,Ken

On Sep 23, 2010, at 2:26 AM, Lex wrote:
The only possible source of this error is when a classloader is unable to load the said class, which is a part of the scala library. So you are either missing the scala library on the classpath or the library jar is corrupt.

You can be missing the library when trying to execute the compiler (nothing gets compiled). Or you can be missing the library when trying to run your tests (tests compile but do not run). In the latter case specifying the scala library as a compile-time dependency may not be enough, and you will have to specify it as a runtime dependency for the tests.


On Thu, Sep 23, 2010 at 12:40 AM, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
I'm experiencing this trying to run the maven test target, but a google search reveals it to be a fairly commonly encountered error. One cause seems to be that the scala library isn't on the classpath/in the list of dependencies, but as far as I can tell, maven has all the necessary info to find the scala 2.8.0 library. Any suggestions as to how to go about tracking down the actual source of this error? The stack trace quickly gets into class loaders, which is all black magic to me...

Thanks,
Ken



david.bernard
Joined: 2009-01-08,
User offline. Last seen 1 year 27 weeks ago.
Re: How to track down "java.lang.NoClassDefFoundError: scala/Sc
Could you try the sample project I sent you (in other thread) ?

On Thu, Sep 23, 2010 at 19:00, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
Quick note: found this on the maven site:
  • compile
    This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects
So, in theory, the scala library should be available to the "test" phase of the lifecycle, if I'm not misreading this. Just to check I added in the dependency:
      <dependency>        <groupId>org.scala-lang</groupId>        <artifactId>scala-library</artifactId>         <version>${scala.version}</version>
   <scope>test</scope>
      </dependency>

and got the same error I've been getting, i.e. scala/ScalaObject unknown.
Thanks,Ken


On Sep 23, 2010, at 11:53 AM, Kenneth McDonald wrote:
Hi everyone, thanks for all the help.
First of all, here's the result of mvn -v. As far as I know this is an up to date version of maven.
Apache Maven 2.2.1 (r801777; 2009-08-06 14:16:01-0500)Java version: 1.6.0_20Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/HomeDefault locale: en_US, platform encoding: MacRoman OS name: "mac os x" version: "10.6.4" arch: "i386" Family: "mac"
Next, I've already deleted scala-lang (thanks to David Bernard for how to do this) and it's been reloaded, so I doubt it's a corruption problem there.
The compile phase does work. I have debug mode turned on for maven, and the relevant line on the console output is:
[DEBUG] cmd:  /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java -classpath /Users/Ken/.m2/repository/org/scala-lang/scala-library/2.8.0/scala-library-2.8.0.jar:/Users/Ken/.m2/repository/org/scala-lang/scala-compiler/2.8.0/scala-compiler-2.8.0.jar:/Users/Ken/.m2/repository/org/scala-tools/maven-scala-plugin/2.14.2-SNAPSHOT/maven-scala-plugin-2.14.2-SNAPSHOT.jar -Xbootclasspath/a:/Users/Ken/.m2/repository/org/scala-lang/scala-library/2.8.0/scala-library-2.8.0.jar org_scala_tools_maven_executions.MainWithArgsInFile scala.tools.nsc.Main /private/var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/scala-maven-6531627448163474925.args
So the library is included there.
When I try a test, I get a command of a very different nature:
Forking command line: /bin/sh -c cd /Users/Ken/mvn_projects/rex && /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java -jar /var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/surefirebooter7092588256684063981.jar /var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/surefire7499230852803569407tmp /var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/surefire6657987389890315523tmp
No explicit mention of the scala library. Does the test phase move that lib into one of the temp folders? That wouldn't make much sense, IMHO. But the scala lib is included as an unscoped dependency in my pom file:
      <dependency>        <groupId>org.scala-lang</groupId>        <artifactId>scala-library</artifactId>        <version>${scala.version}</version>       </dependency>
Since it's unscoped, I assumed it would apply to all of the maven phases. (I'm still very much learning maven on a "need to know" basis.")
I will read up on how to include this as a runtime dependency for the tests, but if any of the above strikes you as suspicious, please post.
Thanks,Ken

On Sep 23, 2010, at 2:26 AM, Lex wrote:
The only possible source of this error is when a classloader is unable to load the said class, which is a part of the scala library. So you are either missing the scala library on the classpath or the library jar is corrupt.

You can be missing the library when trying to execute the compiler (nothing gets compiled). Or you can be missing the library when trying to run your tests (tests compile but do not run). In the latter case specifying the scala library as a compile-time dependency may not be enough, and you will have to specify it as a runtime dependency for the tests.


On Thu, Sep 23, 2010 at 12:40 AM, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
I'm experiencing this trying to run the maven test target, but a google search reveals it to be a fairly commonly encountered error. One cause seems to be that the scala library isn't on the classpath/in the list of dependencies, but as far as I can tell, maven has all the necessary info to find the scala 2.8.0 library. Any suggestions as to how to go about tracking down the actual source of this error? The stack trace quickly gets into class loaders, which is all black magic to me...

Thanks,
Ken




bmjsmith
Joined: 2010-03-12,
User offline. Last seen 42 years 45 weeks ago.
Re: How to track down "java.lang.NoClassDefFoundError: scala/Sc
Hi Ken
Your command line for surefire looks fine.
The two tmp files on it contain the classpaths and directories used by surefire.
Examine the contents of the first - I suspect there is something wrong with it.
Mine (windoze) contains amongst others this entry:
classPathUrl.2=C\:\\Users\\brian\\.m2\\repository\\org\\scala-lang\\scala-library\\2.8.0\\scala-library-2.8.0.jar
I would guess yours either doesn't, or has an invalid location specified or a location that surefire cannot parse or reach maybe?
regards
Brian
On 23 September 2010 17:53, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
Hi everyone, thanks for all the help.
First of all, here's the result of mvn -v. As far as I know this is an up to date version of maven.
Apache Maven 2.2.1 (r801777; 2009-08-06 14:16:01-0500)Java version: 1.6.0_20Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/HomeDefault locale: en_US, platform encoding: MacRoman OS name: "mac os x" version: "10.6.4" arch: "i386" Family: "mac"
Next, I've already deleted scala-lang (thanks to David Bernard for how to do this) and it's been reloaded, so I doubt it's a corruption problem there.
The compile phase does work. I have debug mode turned on for maven, and the relevant line on the console output is:
[DEBUG] cmd:  /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java -classpath /Users/Ken/.m2/repository/org/scala-lang/scala-library/2.8.0/scala-library-2.8.0.jar:/Users/Ken/.m2/repository/org/scala-lang/scala-compiler/2.8.0/scala-compiler-2.8.0.jar:/Users/Ken/.m2/repository/org/scala-tools/maven-scala-plugin/2.14.2-SNAPSHOT/maven-scala-plugin-2.14.2-SNAPSHOT.jar -Xbootclasspath/a:/Users/Ken/.m2/repository/org/scala-lang/scala-library/2.8.0/scala-library-2.8.0.jar org_scala_tools_maven_executions.MainWithArgsInFile scala.tools.nsc.Main /private/var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/scala-maven-6531627448163474925.args
So the library is included there.
When I try a test, I get a command of a very different nature:
Forking command line: /bin/sh -c cd /Users/Ken/mvn_projects/rex && /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java -jar /var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/surefirebooter7092588256684063981.jar /var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/surefire7499230852803569407tmp /var/folders/J6/J6Md7QzoH-apMu-1gFqvaE+++TM/-Tmp-/surefire6657987389890315523tmp
No explicit mention of the scala library. Does the test phase move that lib into one of the temp folders? That wouldn't make much sense, IMHO. But the scala lib is included as an unscoped dependency in my pom file:
      <dependency>        <groupId>org.scala-lang</groupId>        <artifactId>scala-library</artifactId>        <version>${scala.version}</version>       </dependency>
Since it's unscoped, I assumed it would apply to all of the maven phases. (I'm still very much learning maven on a "need to know" basis.")
I will read up on how to include this as a runtime dependency for the tests, but if any of the above strikes you as suspicious, please post.
Thanks,Ken

On Sep 23, 2010, at 2:26 AM, Lex wrote:
The only possible source of this error is when a classloader is unable to load the said class, which is a part of the scala library. So you are either missing the scala library on the classpath or the library jar is corrupt.

You can be missing the library when trying to execute the compiler (nothing gets compiled). Or you can be missing the library when trying to run your tests (tests compile but do not run). In the latter case specifying the scala library as a compile-time dependency may not be enough, and you will have to specify it as a runtime dependency for the tests.


On Thu, Sep 23, 2010 at 12:40 AM, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
I'm experiencing this trying to run the maven test target, but a google search reveals it to be a fairly commonly encountered error. One cause seems to be that the scala library isn't on the classpath/in the list of dependencies, but as far as I can tell, maven has all the necessary info to find the scala 2.8.0 library. Any suggestions as to how to go about tracking down the actual source of this error? The stack trace quickly gets into class loaders, which is all black magic to me...

Thanks,
Ken



Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland