Redian新闻
>
htmlunit中的classpath问题,总是找不到package
avatar
htmlunit中的classpath问题,总是找不到package# Java - 爪哇娇娃
j*3
1
用的ubuntu12.04 64bit
我把htmlunit那个lib文件都拷贝到lib的目录下,设置了classpath,但是每次complie
都出错。
求助各位,折腾了好久不知道什么问题
Debugging information as follows:
[email protected]:~$ echo $CLASSPATH
/home/jnsong:/home/jnsong/Downloads/htmlunit-2.10/lib
_____________________________________________
[email protected]:~$ javac myClient.java
myClient.java:6: error: package com.gargoylesoftware.htmlunit does not exist
import com.gargoylesoftware.htmlunit.Page;
^
myClient.java:7: error: package com.gargoylesoftware.htmlunit does not exist
import com.gargoylesoftware.htmlunit.WebClient;
^
myClient.java:8: error: package com.gargoylesoftware.htmlunit does not exist
import com.gargoylesoftware.htmlunit.HtmlPage2;
^
myClient.java:13: error: cannot find symbol
WebClient webClient = new WebClient();
^
symbol: class WebClient
location: class myClient
myClient.java:13: error: cannot find symbol
WebClient webClient = new WebClient();
^
symbol: class WebClient
location: class myClient
myClient.java:14: error: cannot find symbol
HtmlPage page = webClient.getPage("http://google.com"); // Pass in URL
^
symbol: class HtmlPage
location: class myClient
6 errors
[email protected]:~$ ^
__________________________________________________________
myclient.java 的程序内容
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.lang.String;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
public class myClient {
public static void main(String[] args) throws Exception {
// Create and initialize WebClient object
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://google.com"); // Pass in URL
Console.out.println(page.toString());
}
}
谢谢了!
avatar
T*U
2
your are using jar files, rite?
add this to your classpath
/home/jnsong/Downloads/htmlunit-2.10/lib/*.jar

complie
exist

【在 j******3 的大作中提到】
: 用的ubuntu12.04 64bit
: 我把htmlunit那个lib文件都拷贝到lib的目录下,设置了classpath,但是每次complie
: 都出错。
: 求助各位,折腾了好久不知道什么问题
: Debugging information as follows:
: [email protected]:~$ echo $CLASSPATH
: /home/jnsong:/home/jnsong/Downloads/htmlunit-2.10/lib
: _____________________________________________
: [email protected]:~$ javac myClient.java
: myClient.java:6: error: package com.gargoylesoftware.htmlunit does not exist

avatar
j*3
3
谢谢你的回复。请问那个路径是在哪里设置
我尝试用
vim .bashrc
加入了一行
export CLASSPATH="/jar locations/*.jar"
然后source .bashrc
同时用
sudo vim /etc/environment 里面加入类似的
CLASSPATH="/jar locations/*.jar"
Reboot
还是提示同样的错误。。。。

【在 T****U 的大作中提到】
: your are using jar files, rite?
: add this to your classpath
: /home/jnsong/Downloads/htmlunit-2.10/lib/*.jar
:
: complie
: exist

avatar
T*U
4
show me your current classpath

【在 j******3 的大作中提到】
: 谢谢你的回复。请问那个路径是在哪里设置
: 我尝试用
: vim .bashrc
: 加入了一行
: export CLASSPATH="/jar locations/*.jar"
: 然后source .bashrc
: 同时用
: sudo vim /etc/environment 里面加入类似的
: CLASSPATH="/jar locations/*.jar"
: Reboot

avatar
j*3
5
[email protected]:~/lib$ echo $CLASSPATH
/home/jnsong/Downloads/htmlunit-2.11/lib/*.jar
In /etc/environment, I have
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/
games"
export CLASSPATH="/home/jnsong/lib/*.jar"
in my .bashrc, I have
export CLASSPATH="/home/jnsong/Downloads/htmlunit-2.11/lib/*.jar"
in that lib folder, I have:
[email protected]:~/Downloads/htmlunit-2.11/lib$ ls
commons-codec-1.7.jar jetty-http-8.1.7.v20120910.jar
commons-collections-3.2.1.jar jetty-io-8.1.7.v20120910.jar
commons-io-2.4.jar jetty-util-8.1.7.v20120910.jar
commons-lang3-3.1.jar jetty-websocket-8.1.7.v20120910.jar
commons-logging-1.1.1.jar myClient.java
cssparser-0.9.8.jar nekohtml-1.9.17.jar
htmlunit-2.11.jar sac-1.3.jar
htmlunit-core-js-2.11.jar serializer-2.7.1.jar
httpclient-4.2.2.jar xalan-2.7.1.jar
httpcore-4.2.2.jar xercesImpl-2.10.0.jar
httpmime-4.2.2.jar xml-apis-1.4.01.jar
[email protected]:~/Downloads/htmlunit-2.11/lib$
Thanks a lot for your help and time!

【在 T****U 的大作中提到】
: show me your current classpath
avatar
T*U
6
try change it to
/home/jnsong/Downloads/htmlunit-2.11/lib/*
or use
javac -cp /home/jnsong/Downloads/htmlunit-2.11/lib/* yourprogram

【在 j******3 的大作中提到】
: [email protected]:~/lib$ echo $CLASSPATH
: /home/jnsong/Downloads/htmlunit-2.11/lib/*.jar
: In /etc/environment, I have
: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/
: games"
: export CLASSPATH="/home/jnsong/lib/*.jar"
: in my .bashrc, I have
: export CLASSPATH="/home/jnsong/Downloads/htmlunit-2.11/lib/*.jar"
: in that lib folder, I have:
: [email protected]:~/Downloads/htmlunit-2.11/lib$ ls

avatar
j*3
7
我把路径末尾的".jar"去掉了,
现在再编译myClient.java 提示是这样:
[email protected]:~$ javac myClient.java
myClient.java:13: error: cannot find symbol
HtmlPage page = webClient.getPage("http://google.com"); // Pass in URL
^
symbol: class HtmlPage
location: class myClient
1 error
如果直接用你说的第二种方法,提示:
[email protected]:~$ javac -cp /home/jnsong/Downloads/htmlunit-2.11/lib/*
myClient.java
javac: invalid flag: /home/jnsong/Downloads/htmlunit-2.11/lib/commons-
collections-3.2.1.jar
Usage: javac
use -help for a list of possible options
[email protected]:~$
还是不行,谢谢你,不过比起之前,error现在就一个,就是说找不到symbol。
avatar
T*U
8
在.java里面加
import com.gargoylesoftware.htmlunit.html
or
import com.gargoylesoftware.htmlunit.*
你如果不熟java和linux的话,最好先在windows下用eclipse或其他IDE编译通过后再上
linux

【在 j******3 的大作中提到】
: 我把路径末尾的".jar"去掉了,
: 现在再编译myClient.java 提示是这样:
: [email protected]:~$ javac myClient.java
: myClient.java:13: error: cannot find symbol
: HtmlPage page = webClient.getPage("http://google.com"); // Pass in URL
: ^
: symbol: class HtmlPage
: location: class myClient
: 1 error
: 如果直接用你说的第二种方法,提示:

avatar
j*3
9
ThinkU,谢谢你的帮助,我那个问题已经解决了,就是你说的,import的时候用*,就不
报错了。我还在继续学习中。感谢!
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。