简体   繁体   English

将多个jar文件添加到类路径

[英]Adding multiple jar files into classpath

I am trying to add all the jar files in the directory below but I get 我正在尝试在下面的目录中添加所有jar文件,但我得到了

Exception in thread "main" java.lang.NoClassDefFoundError: twitter4j/TwitterException error. 线程“主”中的异常java.lang.NoClassDefFoundError:twitter4j / TwitterException错误。

I am sure there is TwitterException class inside the .jar file. 我确定.jar文件中有TwitterException类。 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. 我正在使用ubuntu和jdk 1.7。 I tried the same command in windows and it works flawlessly. 我在Windows中尝试了相同的命令,它可以完美运行。 Is there anything special to do related to Ubuntu OS? 与Ubuntu OS相关的事情有什么特别的吗?

The * syntax for classpaths is rather limited. 类路径的*语法相当有限。 Try: 尝试:

java -classpath "~/twitter4j-2.2.6/lib/*:." GetHashtag

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

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