我正在制作YouTube广播示例java程序。我已经从
创建了一个示例程序导入代码https://github.com/youtube/api-samples/tree/master/java
并且,我已导入必要的依赖项/ jar。但是,当我尝试运行程序时,它会抛出异常:
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
答案 0 :(得分:3)
如果您使用的是maven,请在pom.xml
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.5</version>
</dependency>
否则,您可以下载此jar org.mortbay.jetty.jar
并将其包含在内。