3

When I run a scala jar, it throws the following error message:

Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    at com.ebay.twitch.Main.main(Main.scala)
Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    ... 13 more

But I check my jar that the scala-lang.jar is in the lib folder, so it should be in classpath. But why here it can not find it?

Jeff Zhang

zjffdu
  • 25,496
  • 45
  • 109
  • 159
  • But I use jar -xvf myjar.jar to extract my jar, and find the scala-library.jar in the lib folder – zjffdu Jun 16 '11 at 10:56
  • 1
    "... and find the scala-library.jar ..." but do you actually have it on the classpath? I.e., have you set the approprite key in the manifest file? The Java VM does not automatically start using a JAR, just because it is contained in some subfolder stored in another JAR. You have to tell it, that it must use the contained JAR. – Dirk Jun 16 '11 at 11:10
  • 1
    Upon reading the documentation... "Note: The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path." (http://download.oracle.com/javase/tutorial/deployment/jar/downman.html) – Dirk Jun 16 '11 at 11:18

2 Answers2

1

Please read question classpath-including-jar-within-a-jar.

Community
  • 1
  • 1
Dirk
  • 30,623
  • 8
  • 82
  • 102
0

Sorry, I make a stupid mistake. Actually I run scala in hadoop, and call "hadoop -jar" rather than "hadoop jar", such a stupid mistake.

zjffdu
  • 25,496
  • 45
  • 109
  • 159