`
单眼皮大娘
  • 浏览: 111045 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

Building and Installing the Basic Demo

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

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.


我配置好CLASSPATH,可是结果如下:

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.

百思不得其解。不知为何总出现这样的结果。后来改变了命令行的输入,问题解决,就这么个小小的错误,耗费了N个小时。
新输入的命令行:
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


结果如下:
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


接着输入检索命令结果如下:
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:


问题还好解决。

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

百度有时候真是搜不出什么结果,这是就应该想google看齐。google的英文检索那真是没得说,而且国外资料确实要比国内全而且准。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics