Reputation: 67
This is my first time working with the twitter4j API to download twitter tweets. I am using Eclipse->Maven to set dependencies on the twitter4j-core-4.0.4.jar.
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>4.0.4</version>
</dependency>
I run my project jar on a remote university unix system. My runnable jar(27MB) runs fine without any issues but my non-runnable jar(10KB) fails with the below error.
Exception in thread "main" java.lang.NoClassDefFoundError: twitter4j/TwitterException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2570)
at java.lang.Class.getMethod0(Class.java:2813)
at java.lang.Class.getMethod(Class.java:1663)
The "Libraries" and "order and Export" sections in "Java build path" properties of the project do have the Maven Dependencies included.
I cannot submit the the runnable jar as it is too large. I am not sure why the error as I have successfully run other similar programs using external jars before.
I am new to Maven and Twitter4j so I suspect this can be a known issue.
Upvotes: 1
Views: 1656
Reputation: 67
I think I got the solution for this. It seems this was a basic concept that I wasn't aware of. The non runnable project jar cannot access its external jar dependencies during runtime. The jar locations have to be specifically mentioned using the classpath variable. In my case, since I use hadoop on unix to execute jar, I did the below and it worked.
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:/home/005/s/ss/ssp151830/twitter4j-core-4.0.2.jar
In case you use just plain java, you update the java classpath variable.
Upvotes: 1