简体   繁体   English

在Mac上为Lucene设置Java类路径

[英]Setting java classpath for lucene on a mac

I downloaded the lucene jars and then added them to the CLASSPATH variable via my .bash_profile, the paths to the jars display correctly in the terminal. 我下载了lucene jar,然后通过我的.bash_profile将它们添加到CLASSPATH变量中,jar的路径在终端中正确显示。

export CLASSPATH=/Users/dk/lucene-3.4.0/lucene-core-3.4.0.jar
export CLASSPATH=$CLASSPATH:/Users/dk/lucene-3.4.0/contrib/demo/lucene-demo-3.4.0.jar

echo $CLASSPATH
/Users/dk/lucene-3.4.0/lucene-core-3.4.0.jar:/Users/dk/lucene-3.4.0/contrib/demo/lucene-demo-3.4.0.jar

However, java still complains to me when I try to run the demo: 但是,当我尝试运行演示时,java仍然向我抱怨:

java org.apache.lucene.demo.IndexFiles -docs .

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/demo/IndexFiles
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.demo.IndexFiles
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
......

I was able to follow this exact procedure to get the lucene demo working on an ubuntu machine, now I just want it to be able to run on my mac. 我能够按照这个确切的过程来使lucene演示在ubuntu机器上工作,现在我只希望它能够在我的mac上运行。 It seems there are similar questions floating around stackoverflow but none of them seem to answer this question. 似乎围绕着stackoverflow漂浮着类似的问题,但是似乎没有一个人回答这个问题。

As of Lucene 6.0, these seem to work: 从Lucene 6.0开始,这些似乎有效:

java -cp ./core/lucene-core-6.0.0.jar:./analysis/common/lucene-analyzers-common-6.0.0.jar:./demo/lucene-demo-6.0.0.jar  org.apache.lucene.demo.IndexFiles -docs <directory to index>

For the search demo: 对于搜索演示:

java -cp ./core/lucene-core-6.0.0.jar:./analysis/common/lucene-analyzers-common-6.0.0.jar:./queryparser/lucene-queryparser-6.0.0.jar:./demo/lucene-demo-6.0.0.jar  org.apache.lucene.demo.SearchFiles

Are you sure you have your paths right? 您确定您的路径正确吗? It works fine for me. 这对我来说可以。

.../lucene-3.4.0/tmp $ ls
lucene-core-3.4.0.jar   lucene-demo-3.4.0.jar
.../lucene-3.4.0/tmp $ export CLASSPATH=./lucene-core-3.4.0.jar:./lucene-demo-3.4.0.jar
.../lucene-3.4.0/tmp $ echo $CLASSPATH
./lucene-core-3.4.0.jar:./lucene-demo-3.4.0.jar
.../lucene-3.4.0/tmp $ java org.apache.lucene.demo.IndexFiles -docs .
Indexing to directory 'index'...
adding ./lucene-core-3.4.0.jar
adding ./lucene-demo-3.4.0.jar
1485 total milliseconds
.../lucene-3.4.0/tmp $

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM