java linux中http包的导入错误

时间:2014-04-01 07:22:03

标签: java linux

您好我使用linux,当我尝试导入以下软件包时,编译错误。

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;

import com.google.gson.Gson;

如何在我的linux中安装这些软件包然后进行编译。我的代码如下,

class pojo1
{
  String name=abc;
  String age=18;
  //generate setter and getters
}

public class SimpleURL
{
public static void main(String[] args)
    {
    String postUrl="www.site.com";// put in your url
    Gson gson= new Gson();
    HttpPost post = new HttpPost(postUrl);
    StringEntity  postingString = new StringEntity(gson.toJson(pojo1));//convert your pojo to   json
    post.setEntity(postingString);
    post.setHeader("Content-type","application/json");
    HttpResponse  response = httpClient.execute(post);
    }
} 

1 个答案:

答案 0 :(得分:0)

尝试

javac -cp。; httpclient.jar MyClass.java

java -cp .; httpclient.jar MyClass