我正在尝试用HtmlUnit设置我的第一个示例程序。这是代码:
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.WebClient;
public class test {
public static void main(String[] args) throws Exception {
WebClient client = new WebClient();
HtmlPage currentPage = client.getPage("http://www.oddsportal.com/matches/soccer");
client.waitForBackgroundJavaScript(10000);
String textSource = currentPage.asXml();
System.out.println(textSource);
}
}然后我编译:
javac -cp lib/htmlunit单元-2.9.jar test.java
但当我试着做测试的时候
java -cp lib/htmlunit单元-2.9.jar测试
线程"main“中的异常:由: java.net.URLClassLoader$1.run(URLClassLoader.java:217):测试引起的测试( java.security.AccessController.doPrivileged(Native方法))在java.net.URLClassLoader.findClass(URLClassLoader.java:205),java.lang.ClassLoader.loadClass(ClassLoader.java:321),sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294),java.lang.ClassLoader.loadClass(ClassLoader.java:266)找不到主类: test。程序将退出。
问题出在哪里?我没有其他包裹吗?
发布于 2012-04-08 18:57:57
这样做是可行的:
java -cp .:lib/* test
发布于 2012-04-08 16:47:52
您可能必须将当前路径添加到类路径。
在Unix/Linux/Mac上:
java -cp .:lib/htmlunit-2.9.jar test在Windows上:
java -cp .;lib/htmlunit-2.9.jar test编辑实际上只需要htmlunit-2.9.jar就需要更多的jars。因此,考虑到所有所需的jars都位于lib/目录中,实际上应该调用以下内容:
在Unix/Linux/Mac上:
java -cp .:lib/* test如果从shell运行此命令,还需要转义通配符(使用“\”)或将整个类路径放入引号中以避免shell展开。
在Windows上:
java -cp .;lib/* testhttps://stackoverflow.com/questions/10064488
复制相似问题