0

I am trying to add all the jar files in the directory below but I get

Exception in thread "main" java.lang.NoClassDefFoundError: twitter4j/TwitterException error.

I am sure there is TwitterException class inside the .jar file. Is there any error in my classpath syntax ?

mahmut@ubuntu:~/Desktop/Java/TwitterDeneme/bin$ java -classpath "~/twitter4j-2.2.6/lib/*.jar:." GetHashtag
Exception in thread "main" java.lang.NoClassDefFoundError: twitter4j/TwitterException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
    at java.lang.Class.getMethod0(Class.java:2685)
    at java.lang.Class.getMethod(Class.java:1620)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:488)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:480)
Caused by: java.lang.ClassNotFoundException: twitter4j.TwitterException
    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:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 6 more

I am using ubuntu and jdk 1.7. I tried the same command in windows and it works flawlessly. Is there anything special to do related to Ubuntu OS?

1

1 Answer 1

8

The * syntax for classpaths is rather limited. Try:

java -classpath "~/twitter4j-2.2.6/lib/*:." GetHashtag
Sign up to request clarification or add additional context in comments.

5 Comments

By the way, on Windows you need to use ; instead of : for the command to work.
Tried both lib/* and lib/*.jar but no luck! Is it related to wildcard character or any other problem? I also tried to include jar files individually but it gives the same error either. Actually, I compiled the code in windows and just moved class file to ubuntu. Am I missing anything?
Are you sure that class is in any of your jar files?
I found the problem. ~ character inside quotes causes problem. I wrote "/home/mahmut/twitter4j-2.2.6/lib/*:." instead of "~/twitter4j-2.2.6/lib/*:." and it worked. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.