Jumblr的ClassNotFound异常

时间:2013-08-12 03:28:58

标签: java tumblr

我正在使用找到http://tumblr.github.io/jumblr/

的“Jar with dependencies”构建

代码:

import com.tumblr.jumblr.JumblrClient;

public class App {

    public static void main(String[] args)  {
        // Authenticate via OAuth
        JumblrClient client = new JumblrClient(
          "xyz",
          "xyz"
        );
        client.setToken(
          "xyz",
          "xyz"
        );
    }
}

当我使用

进行编译时,是否使用Tumblr的实际密钥并不重要
javac -cp jumblr-0.0.6-jar-with-dependencies.jar App.java

当我用

运行它时
java App

提出

Exception in thread "main" java.lang.NoClassDefFoundError: com/tumblr/jumblr/JumblrClient
        at App.main(App.java:7)
Caused by: java.lang.ClassNotFoundException: com.tumblr.jumblr.JumblrClient
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 1 more

我已将jumblr-0.0.6-jar-with-dependencies.jar放在与App.java相同的文件夹中。

关于例外的任何想法?

1 个答案:

答案 0 :(得分:0)

 -cp <class search path of directories and zip/jar files>
 -classpath <class search path of directories and zip/jar files>
                   A : separated list of directories, JAR archives,
                   and ZIP archives to search for class files.

使用:

javac -cp . App.java

javac -classpath . App.java

假设您当前目录中有jar。

要回答你的编辑:要运行已编译的代码,你应该使用(没有.java扩展名):

java -cp jumblr-0.0.6-jar-with-dependencies.jar App