Java 主类中的ClassNotFoundException

Java 主类中的ClassNotFoundException,java,classpath,httpclient,classnotfoundexception,Java,Classpath,Httpclient,Classnotfoundexception,我正在尝试编写一个Java应用程序,从Yahoo Finance API中提取数据。我使用雅虎的例子作为参考。当I-cp commons-httpclient-3.1.jar时,它可以正确编译。但是,当我运行它时,我得到一个错误,说找不到主类。根据我的研究,我假设这是编译期间存在的类在运行时丢失的结果。有什么建议吗 这里是[完全错误] 这是我正在处理的jar文件-cp'ing: 以下是代码片段: import java.io.*; import org.apache.commons.http

我正在尝试编写一个Java应用程序,从Yahoo Finance API中提取数据。我使用雅虎的例子作为参考。当I-cp commons-httpclient-3.1.jar时,它可以正确编译。但是,当我运行它时,我得到一个错误,说找不到主类。根据我的研究,我假设这是编译期间存在的类在运行时丢失的结果。有什么建议吗

这里是[完全错误]

这是我正在处理的jar文件-cp'ing:

以下是代码片段:

import java.io.*;

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;

public class YahooWebServiceGet {   

public static void main(String[] args) throws Exception {
    String request = "http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=umbrella&results=10";

    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(request);

    // Send GET request
    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + method.getStatusLine());
    }
    InputStream rstream = null;

    // Get the response body
    rstream = method.getResponseBodyAsStream();

    // Process the response from Yahoo! Web Services
    BufferedReader br = new BufferedReader(new InputStreamReader(rstream));
    String line;
    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }
    br.close();
}

}

我可以从您的屏幕截图中看到,您的类路径只引用commons库,而不是您的类。如果类位于当前目录中,请添加;。指向类路径(或将点更改为类所在的目录)。另外,您不希望在要运行的类上指定.class。它将补充这一点

java -cp ~/Downloads/commons-httpclient-3.1.jar;. YahooWebServiceGet

对于java,您不直接指定类文件。它可以在jar中或类路径上的任何位置。因此,您需要提供完整的类路径,然后为java类提供任何包信息,并且不提供.class扩展名。我的包裹我的班级你的课程是什么?您应该添加-cp。运行类文件时,如:

java -cp .;xxx.jar YahooWebServiceGet

您也可以共享异常跟踪吗