首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安装Unirest-Java以使用Mashape

安装Unirest-Java以使用Mashape
EN

Stack Overflow用户
提问于 2013-10-31 14:18:53
回答 2查看 10.3K关注 0票数 1

我创建了这个简单的类:

代码语言:javascript
复制
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();
        }
    }

}

但我知道这个错误:

代码语言:javascript
复制
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元素:

代码语言:javascript
复制
<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那里得到这个:

代码语言:javascript
复制
[WARNING] The POM for com.mashape.unirest:unirest-java:jar:1.3.0-SNAPSHOT is missing, no dependency information available

EN

回答 2

Stack Overflow用户

发布于 2013-11-03 00:28:12

我是Unirest-Java的作者。

请将Unirest更新为其最新版本好吗?这个问题应该已经用1.3.0版本解决了。

还要确保导入了所有必需的依赖项。您可以在https://github.com/Mashape/unirest-java#installing上阅读安装说明

编辑:强制Maven重新下载库,尝试删除~/.m2/repository/com/mashape/unirest/unirest-java/unirest-java文件夹,然后再次执行mvn clean compile

票数 2
EN

Stack Overflow用户

发布于 2013-12-11 00:55:57

使用Maven将所有东西打包到一个uber jar中是明智的。

关于如何在您的帖子项目中使用Unirest,请参阅此。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19708965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档