简体   繁体   English

java.lang.NoClassDefFoundError:twitter4j / TwitterException

[英]java.lang.NoClassDefFoundError: twitter4j/TwitterException

This is my first time working with the twitter4j API to download twitter tweets. 这是我第一次使用twitter4j API下载Twitter微博。 I am using Eclipse->Maven to set dependencies on the twitter4j-core-4.0.4.jar. 我正在使用Eclipse-> Maven在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. 我在远程大学Unix系统上运行项目jar。 My runnable jar(27MB) runs fine without any issues but my non-runnable jar(10KB) fails with the below error. 我的可运行jar(27MB)运行正常,没有任何问题,但是我的不可运行jar(10KB)失败,并出现以下错误。

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. 项目的“ Java构建路径”属性中的“库”和“订购和导出”部分的确包含了Maven依赖关系。

I cannot submit the the runnable jar as it is too large. 我无法提交可运行的jar,因为它太大。 I am not sure why the error as I have successfully run other similar programs using external jars before. 我不确定为什么会出错,因为我之前已经使用外部jar成功运行了其他类似程序。

I am new to Maven and Twitter4j so I suspect this can be a known issue. 我是Maven和Twitter4j的新手,所以我怀疑这可能是一个已知问题。

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. 不可运行的项目jar在运行期间无法访问其外部jar依赖项。 The jar locations have to be specifically mentioned using the classpath variable. 必须使用classpath变量特别提及jar的位置。 In my case, since I use hadoop on unix to execute jar, I did the below and it worked. 就我而言,由于我在unix上使用hadoop来执行jar,所以我做了以下工作。

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. 如果仅使用纯Java,则更新java classpath变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM