3

如何在我的类路径中使用 scala-compiler-2.8.0.jar 和 scala-library-2.8.0.jar 出现此异常?

Exception in thread "main" java.lang.NoClassDefFoundError: scala/Serializable
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at kafka.utils.ZKConfig.<init>(ZkUtils.scala:302)
at kafka.producer.ProducerConfig.<init>(ProducerConfig.scala:25)
at pt.sapo.labs.crawl.twitter.streaming.adapter.MessageBrokerStatusAdapter.<init>(MessageBrokerStatusAdapter.java:30)
at pt.sapo.labs.TwitterStreamClientApplication.createAdapters(TwitterStreamClientApplication.java:73)
at pt.sapo.labs.TwitterStreamClientApplication.start(TwitterStreamClientApplication.java:57)
at pt.sapo.labs.Main.main(Main.java:39)
Caused by: java.lang.ClassNotFoundException: scala.Serializable
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 17 more

这是我的 META-INF/MANIFEST.MF

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Build-Jdk: 1.6.0_24
Main-Class: pt.sapo.labs.Main
Class-Path: lib/twitter4j-async-3.0.4-SNAPSHOT.jar lib/twitter4j-core-
3.0.4-SNAPSHOT.jar lib/twitter4j-stream-3.0.4-SNAPSHOT.jar lib/log4j-
1.2.16.jar lib/jackson-mapper-asl-1.9.5.jar lib/jackson-core-asl-1.9.
5.jar lib/commons-httpclient-3.1.jar lib/commons-logging-1.0.4.jar li
b/commons-codec-1.2.jar lib/httpcore-4.1.4.jar lib/httpclient-4.1.3.j
ar lib/httpmime-4.1.3.jar lib/commons-io-2.3.jar lib/jcl-over-slf4j-1
.6.4.jar lib/slf4j-api-1.6.4.jar lib/wstx-asl-3.2.7.jar lib/stax-api-
1.0.1.jar lib/slf4j-jdk14-1.6.4.jar lib/log4j-over-slf4j-1.6.4.jar li
b/mongo-java-driver-2.7.3.jar lib/kafka_2.9.2-0.7.0.jar lib/zookeeper
-3.3.4.jar lib/zkclient-0.1.jar lib/scala-compiler-2.8.0.jar lib/scal
a-library-2.8.0.jar

我像往常一样运行我的罐子。

java -jar reaction-twitter-streaming-client.jar

我想了解为什么它给了我这个例外。

4

1 回答 1

0

我猜想,Class-Path变量的定义存在一些问题。看这里: docs.oracle.com/javase/tutorial/deployment/jar/downman.htmldocs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html

  1. 您的 META-INF/MANIFEST.MF 文件末尾是否有空行?
  2. 你的相对路径正确吗?(从您的 jar 所在的目录,您可以访问这些库吗?)

如果这些都不起作用。我会用一个库尝试一些玩具示例,并尝试将它放在与您的 jar 文件所在的目录相同的目录中,然后放到某个子目录中,... 看看Class-Path是如何工作的...

于 2013-01-31T09:25:57.747 回答