Mac用户 - 如何在Mac中设置CLASSPATHS(我正在进行Lucene演示) [英] Mac User - How do i set CLASSPATHS in Mac (I'm working on a Lucene Demo)

查看:119
本文介绍了Mac用户 - 如何在Mac中设置CLASSPATHS(我正在进行Lucene演示)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的Apache Lucene演示工作,我要在本教程中设置类路径 http://lucene.apache.org/java/2_3_2/demo.html

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

我已经在网上搜索了这些我发现设置CLASSPATH的2个解决方案:

I've hunted the web and these wer the 2 solutions I found to set CLASSPATH:

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

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

第二个出现错误
-bash: setenv:命令未找到

The second one brings up a error -bash: setenv: command not found

第一个似乎接受了确定但是我尝试了教程中的下一步我收到了错误。下一步是运行以下内容:

The first one seemed to accept ok 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

这给了我错误:


线程main中的异常java.lang.NoClassDefFoundError:org / apache / lucene / demo / IndexFiles

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

这让我相信我的CLASSPATHS没有正确设置。假设这个我是对的吗?我已经尝试过其他教程和演示,并且看到了相同的错误。我是Lucene的新手,也是mac和Unix shell脚本的新手。任何人都知道我是否正确设置CLASSPATH,如果这是错误的原因?

This leads me to believe my CLASSPATHS didnt set correctly. Would I be right in assuming this? I have tried other tutorials and demos and see to get this same error quite a bit. Im new to Lucene and relatively new to mac and Unix shell scripting. Anyone know if I am setting the CLASSPATH correctly and if thats the cause of the errors?

推荐答案

当您设置环境变量时 CLASSPATH 然后默认它只适用于当前进程(即shell进程本身) - 它不适用于您在下一行中启动的java进程。为了使其可用于其他进程,您需要导出该变量。在这种情况下,您可以使用以下内容:

When you set an environment variable like CLASSPATH then by default it only applies to the current process (i.e. the shell process itself) - it isn't available to the java process you launch in the next line. In order 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

这基本上说将CLASSPATH变量设置为其当前值加上lucene jar的位置,并使新变量可用于从此shell启动的任何进程。

This basically says "set the CLASSPATH variable to its current value plus the location of the lucene jar, and make the new variable available to any processes launched from this shell".

但是, java设置类路径的常用方法是使用 -classpath 作为 java 命令本身的一部分。或 -cp 选项。在你的情况下,它看起来像:

However, with java the usual way of setting the classpath is to do it as part of the java command itself, using the -classpath or -cp options. In your case it would look something like:

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

顺便说一句,你在使用 setenv 行是因为 setenv 是C shell中用来设置环境变量的命令,但是默认的Mac shell(以及你正在使用的shell)是 bash ,它无法识别 setenv 并让您知道它无法识别它并显示错误消息: -bash:setenv:找不到命令

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

这篇关于Mac用户 - 如何在Mac中设置CLASSPATHS(我正在进行Lucene演示)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆