新手javac导入库(httpclient)命令行

时间:2014-08-06 05:07:30

标签: java apache

我有这个.java并且无法成功编译它。我从apache网站下载了httpclient apache,并尝试使用以下命令编译它。

javac -cp /httpcomponents-client-4.3.4/lib/*.jar;。 PostToServer.java

import org.apache.http.client.HttpClient;

public class PostToServer {


public final static String postapiURL = "http://www.google.com";

public PostToServer() {

}

public static void main(String[] args) {

    postAPI(postapiURL);

}

public static void postAPI(String urlString) {

    try {

        HttpPost request = new HttpPost(urlString);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

}

这是目录

下的文件
~/CallServer$ ls -l httpcomponents-client-4.3.4/lib/
commons-codec-1.6.jar
commons-logging-1.1.3.jar
fluent-hc-4.3.4.jar
httpclient-4.3.4.jar
httpclient-cache-4.3.4.jar
httpcore-4.3.2.jar
httpmime-4.3.4.jar

编译错误:

Try: sudo apt-get install <selected package>
The program 'import' can be found in the following packages:
 * imagemagick
 * graphicsmagick-imagemagick-compat
Try: sudo apt-get install <selected package>
bash: httpcomponents-client-4.3.4/: Is a directory
public: command not found
bash: //public: No such file or directory
public: command not found
bash: PostToServer.java: line 35: syntax error near unexpected token `('
bash: PostToServer.java: line 35: ` public PostToServer() {'

回答(谢谢你的回答): 所以从网站下载.jar二进制文件后,你基本上必须重命名这些jar文件并将它们移动到org / apache / http / client /,你必须手动创建这些文件夹。

1 个答案:

答案 0 :(得分:1)

你的命令有点偏。 bash将;视为命令分隔符,因此;cp之后的所有内容都是命令(分隔符&#34 ;;&#34;适用于Windows)。然后你的库在一个子文件夹而不是根目录 - 所以这个,

javac -cp /httpcomponents-client-4.3.4/lib/*.jar;. PostToServer.java 

应该是,

javac -cp httpcomponents-client-4.3.4/lib/*.jar:. PostToServer.java