Search code examples
javatumblr

ClassNotFound Exception for Jumblr


I am using the "Jar with dependencies" build which is found http://tumblr.github.io/jumblr/

The code:

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"
        );
    }
}

It doesn't matter if I use the actual keys from Tumblr or not, when I compile with

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

When I run it with

java App

It comes up with

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

I've placed the jumblr-0.0.6-jar-with-dependencies.jar in the same folder as App.java.

Any ideas on the exception?


Solution

  •  -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.
    

    Use:

    javac -cp . App.java
    

    or

    javac -classpath . App.java
    

    Assuming you have the jar in your current directory.

    To answer your Edit: To run the compiled code you should use (without .java extension) :

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