1

我在 Android 上看到了 Twitter4j 的许多错误,但我没有在 Android 上使用它。我将它用于 Bukkit(Minecraft 插件)。出于某种原因,当我将 twitter4j-core-3.0.3.jar 添加到我的项目时,在服务器控制台中加载时出现错误:

[SEVERE] Could not load 'plugins\Test.jar' in folder 'plugins'

org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: twitter4j/TwitterException
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.loadPlugins(CraftServer.java:239)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.<init>(CraftServer.java:217)
        at net.minecraft.server.v1_6_R2.PlayerList.<init>(PlayerList.java:56)
        at net.minecraft.server.v1_6_R2.DedicatedPlayerList.<init>(SourceFile:11)
        at net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.java:106)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:391)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
Caused by: java.lang.NoClassDefFoundError: twitter4j/TwitterException
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
        ... 9 more
Caused by: java.lang.ClassNotFoundException: twitter4j.TwitterException
        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 org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 12 more`

由于我是 Java 新手,所以我真的不明白我在这里做错了什么。这是我的代码(我认为这不是问题,因为插件无法加载......:

                String TWITTER_CONSUMER_KEY = "XXXXXXXX";
            String TWITTER_SECRET_KEY = "XXXXXX";
            String TWITTER_ACCESS_TOKEN = "XXXXXXXXXX";
            String TWITTER_ACCESS_TOKEN_SECRET = "XXXXXX";

            ConfigurationBuilder cb = new ConfigurationBuilder();
            cb.setDebugEnabled(true).setOAuthConsumerKey(TWITTER_CONSUMER_KEY).setOAuthConsumerSecret(TWITTER_SECRET_KEY).setOAuthAccessToken(TWITTER_ACCESS_TOKEN).setOAuthAccessTokenSecret(TWITTER_ACCESS_TOKEN_SECRET);
            TwitterFactory tf = new TwitterFactory(cb.build());
            Twitter twitter = tf.getInstance();
            try {
                Query query = new Query(Username);
                QueryResult result;
                do {
                    result = twitter.search(query);
                    List<Status> tweets = result.getTweets();
                    for (Status tweet : tweets) 
                    {
                        String rawJSON = DataObjectFactory.getRawJSON(tweet);
                        try
                        {
                            BufferedWriter out = new BufferedWriter(new FileWriter((getDataFolder() + File.separator + "TwitterData.txt")));
                            out.write(rawJSON);
                            out.close();
                        }
                        catch (IOException ioe) 
                        {
                            ioe.printStackTrace();
                            System.out.println("Failed to store tweets: " + ioe.getMessage());          
                        }

                    }
                } 
                while ((query = result.nextQuery()) != null);
                System.exit(0);
            } 
            catch (TwitterException te)
            {
                te.printStackTrace();
                System.out.println("Failed to search tweets: " + te.getMessage());
                System.exit(-1);
            }

为什么 Twitter4j 无法正确加载?谢谢!

编辑:另外,twitter4j-core-3.03.jar 在我电脑的另一个目录中。这是一个问题吗?

4

1 回答 1

1

Java 程序所需的所有 jar 文件都必须位于服务器的类路径中。在您的情况下,这包括 Twitter4J。

于 2014-01-01T14:40:06.493 回答