0

この単純なクラスを作成しました:

import javax.swing.JOptionPane;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class TweetSent {

    public static void main(String[] args) {
        try {
            HttpResponse<JsonNode> request = Unirest.get("https://intridea-tweetsentiments.p.mashape.com/twitsentiment/?num_tweets=10&query=%3Cquery%3E").basicAuth("X-Mashape-Authorization", "#######################").asJson();
            JOptionPane.showMessageDialog(null,"request: "+request);
        } catch (UnirestException e) {
            JOptionPane.showMessageDialog(null,"ERROR: "+e);
            e.printStackTrace();
        }
    }

}

しかし、私はこのエラーが発生します:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64
    at com.mashape.unirest.request.HttpRequest.basicAuth(HttpRequest.java:61)
    at com.NR.V.TweetSent.main(TweetSent.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64

編集:

ファイルに記載されているすべての<repository>要素を削除しました。pom.xml

<dependency>
    <groupId>com.mashape.unirest</groupId>
    <artifactId>unirest-java</artifactId>
    <version>1.3.0-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.3</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpasyncclient</artifactId>
    <version>4.0-beta4</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpmime</artifactId>
    <version>4.3</version>
</dependency>
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20090211</version>
</dependency>

私はMavenからこれを取得します:

[WARNING] The POM for com.mashape.unirest:unirest-java:jar:1.3.0-SNAPSHOT is missing, no dependency information available

ここに画像の説明を入力

4

2 に答える 2

2

私はUnirest-Javaの作者です。

Unirest を最新バージョンにアップデートしていただけますか? この問題は、バージョン で修正されているはず1.3.0です。

また、必要な依存関係がすべてインポートされていることを確認してください。https://github.com/Mashape/unirest-java#installingでインストール手順を読むことができます

編集: Maven に強制的にライブラリを再ダウンロードさせるには、unirest-javaフォルダを削除してから再度~/.m2/repository/com/mashape/unirest/unirest-java/実行してくださいmvn clean compile

于 2013-11-03T00:28:12.733 に答える
1

Maven を使用して、すべてを 1 つの uber jar にパッケージ化することをお勧めします。

Java プロジェクトで Unirest を使用する方法については、この投稿を参照してください。

于 2013-12-11T00:55:57.610 に答える