Building and Installing the Basic Demo

想运行一下Lucene官网上的小程序,配置好Classpath可是还是不能运行。原文信息如下:

[color=blue]Once you've gotten this far you're probably itching to go. Let's build an index! Assuming you've set your CLASSPATH correctly, just type:

java org.apache.lucene.demo.IndexFiles -docs {path-to-lucene}/src
This will produce a subdirectory called index which will contain an index of all of the Lucene source code.
To search the index type:

java org.apache.lucene.demo.SearchFiles
You'll be prompted for a query. Type in a swear word and press the enter key. You'll see that the Lucene developers are very well mannered and get no results. Now try entering the word "string". That should return a whole bunch of documents. The results will page at every tenth result and ask you whether you want more results.
[/color]

我配置好CLASSPATH,可是结果如下:
[color=red]
D:\>java org.apache.lucene.demo.IndexFiles -docs F:\lib\lucene\lucene-3.5.0-src\
lucene-3.5.0\contrib\demo\src\java\org\apache\lucene\demo
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/dem
o/IndexFiles
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.demo.IndexFiles
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: org.apache.lucene.demo.IndexFiles. Program will
exit.
[/color]
百思不得其解。不知为何总出现这样的结果。后来改变了命令行的输入,问题解决,就这么个小小的错误,耗费了N个小时。
新输入的命令行:
[color=darkblue]D:\>java -cp C:\abc\lucene-core-3.5.0.jar;C:\abc\lucene-demo-3.5.0.jar org.apache.lucene.demo.IndexFiles -docs F:\lib\lu
cene\lucene-3.5.0-src\lucene-3.5.0\contrib\demo\src\java\org\apache\lucene\demo[/color]

结果如下:
[color=darkblue]Indexing to directory 'index'...
adding F:\lib\lucene\lucene-3.5.0-src\lucene-3.5.0\contrib\demo\src\java\org\apache\lucene\demo\IndexFiles.java
adding F:\lib\lucene\lucene-3.5.0-src\lucene-3.5.0\contrib\demo\src\java\org\apache\lucene\demo\SearchFiles.java
407 total milliseconds[/color]

接着输入检索命令结果如下:
[color=cyan]D:\>java -cp C:\abc\lucene-core-3.5.0.jar;C:\abc\lucene-demo-3.5.0.jar org.apache.lucene.demo.SearchFiles
Enter query:
String
Searching for: string
2 total matching documents
1. F:\lib\lucene\lucene-3.5.0-src\lucene-3.5.0\contrib\demo\src\java\org\apache\lucene\demo\SearchFiles.java
2. F:\lib\lucene\lucene-3.5.0-src\lucene-3.5.0\contrib\demo\src\java\org\apache\lucene\demo\IndexFiles.java
Press (q)uit or enter number to jump to a page.

Enter query:[/color]

问题还好解决。

[color=red]注: -CP命令:-cp 参数后面是类路径,是指定给解释器到哪里找到你的.class文件。[/color]

百度有时候真是搜不出什么结果,这是就应该想google看齐。google的英文检索那真是没得说,而且国外资料确实要比国内全而且准。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值