Home:ALL Converter>Setting java classpath for lucene on a mac

Setting java classpath for lucene on a mac

Ask Time:2011-10-25T12:16:23         Author:Dan Q

Json Formatter

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.

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 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. It seems there are similar questions floating around stackoverflow but none of them seem to answer this question.

Author:Dan Q,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7884647/setting-java-classpath-for-lucene-on-a-mac
Dave Newton :

Are you sure you have your paths right? It works fine for me.\n\n.../lucene-3.4.0/tmp $ ls\nlucene-core-3.4.0.jar lucene-demo-3.4.0.jar\n.../lucene-3.4.0/tmp $ export CLASSPATH=./lucene-core-3.4.0.jar:./lucene-demo-3.4.0.jar\n.../lucene-3.4.0/tmp $ echo $CLASSPATH\n./lucene-core-3.4.0.jar:./lucene-demo-3.4.0.jar\n.../lucene-3.4.0/tmp $ java org.apache.lucene.demo.IndexFiles -docs .\nIndexing to directory 'index'...\nadding ./lucene-core-3.4.0.jar\nadding ./lucene-demo-3.4.0.jar\n1485 total milliseconds\n.../lucene-3.4.0/tmp $\n",
2011-10-25T04:56:48
yy