Mac User - How to install CLASSPATHS on Mac (I'm working on a Lucene demo)

I'm trying to get my demo version of Apache Lucene to work, and I got to setting the classpath in this tutorial http://lucene.apache.org/java/2_3_2/demo.html

I hunted the internet and I found 2 solutions that I found to install CLASSPATH:

CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar 

and

 setenv CLASSPATH ${CLASSPATH}:/Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar 

The second causes an error - bash: setenv: command not found

The first one seemed to accept approval, but wen I tried the next step in the tutorial, I got an error. The next step was to run the following:

 Phil-hunters-MacBook:webapps philhunter$ java org.apache.lucene.demo.IndexFiles /Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/src 

which gave me an error:

Exception in thread "main" java.lang.NoClassDefFoundError: org / apache / lucene / demo / IndexFiles

It makes me believe that my CLASSPATHS did not install correctly. Would I be right to suggest this? I tried other lessons and demos and see to get the same error quite a bit. Im new to Lucene and relatively new to Mac and Unix scripts. Does anyone know if I am installing CLASSPATH correctly, and if this is the cause of the errors?

+4
source share
3 answers

When you set the environment variable as CLASSPATH , by default it applies only to the current process (i.e. the shell process itself) - it is not available for the Java process that you run on the next line. To make it available to other processes, you need to "export" the variable. In this case, you can use something like:

 export CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar 

Basically it says: "Set the CLASSPATH variable to the current value plus the location of the lucene banner and make the new variable available to any processes running from this shell."

However, using java, the usual way to set the class path is to execute it as part of the java command itself using the -classpath or -cp . In your case, it will look something like this:

 Phil-hunters-MacBook:webapps philhunter$ java -cp /Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar org.apache.lucene.demo.IndexFiles /Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/src 

As an aside, the error you see when using the setenv line is that setenv is the command used in the C shell to set environment variables, but the default Mac shell (and the shell you use) is bash that doesn't recognize setenv and lets you know that it does not recognize it with the error message: -bash: setenv: command not found .

+5
source

in terminal type

 $ vim ~/.bash_profile 

edit the file and add one line:

 export CLASSPATH=${CLASSPATH}:/usr/local/lucene-3.6.2/lucene-core-3.6.2.jar:/usr/local/lucene-3.6.2/contrib/demo/lucene-demo-3.6.2.jar; 

Be sure to change your path.

Along the way, you lose adding lucene-demo-3.0.3.jar to your classpath.

+5
source

I create a .bash_profile file in my home directory and do something like

 export GRAILS_HOME=/usr/share/grails ... export PATH=${GRAILS_HOME}/bin:${GROOVY_HOME}/bin:/usr/local/mysql-5.1.45-osx10.6-x86_64/bin:${PATH} 

you can do this to set the class path - these examples show how to declare an environment variable and how to use the variable in other variables.

+1
source

Source: https://habr.com/ru/post/1338019/


All Articles