3

我正在开发 YouTube 广播示例 java 程序。我创建了一个示例程序,从

https://github.com/youtube/api-samples/tree/master/java

而且,我已经导入了必要的依赖项/jars。但是,当我尝试运行程序时,它会在这一行抛出异常:

LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

以下例外:

Throwable: org/mortbay/jetty/Handler
java.lang.NoClassDefFoundError: org/mortbay/jetty/Handler
    at com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver$Builder.build(LocalServerReceiver.java:169)
    at com.google.api.services.samples.youtube.cmdline.live.Auth.authorize(Auth.java:80)
    at com.google.api.services.samples.youtube.cmdline.live.CreateBroadcast.main(CreateBroadcast.java:55)
Caused by: java.lang.ClassNotFoundException: org.mortbay.jetty.Handler
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 3 more

当我导入org.mortbay.jetty.jar

我得到这个例外:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/api/client/extensions/java6/auth/oauth2/VerificationCodeReceiver
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver$Builder.build(LocalServerReceiver.java:180)
    at HelloWorld.main(HelloWorld.java:7)
Caused by: java.lang.ClassNotFoundException: com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 14 more
4

1 回答 1

5

如果您使用的是 maven,请将此 jar 包含在您的pom.xml

<dependency>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty</artifactId>
    <version>6.1.5</version>
</dependency>

否则,您可以下载此 jarorg.mortbay.jetty.jar并将其包含在内。

于 2015-05-22T04:41:38.553 回答