简体   繁体   English

Mac索引和CLASSPATH问题-java.lang.NoClassDefFoundError

[英]Mac Indexing and CLASSPATH problems - java.lang.NoClassDefFoundError

System properties: Java 1.6 Mac OSX version 10 Ant 1.8 系统属性:Java 1.6 Mac OSX版本10 Ant 1.8

Scenario: I am working on my final year project which is to create a website which uses Lucene to search my website and my database. 场景:我正在完成我的最后一个项目,即创建一个使用Lucene搜索我的网站和数据库的网站。 I am working through lucene demos here http://lucene.apache.org/java/2_3_2/demo.html which talks about classpath http://lucene.apache.org/java/2_3_2/demo3.html and a web example 我正在通过http://lucene.apache.org/java/2_3_2/demo.html上的lucene演示进行工作,其中讨论了类路径http://lucene.apache.org/java/2_3_2/demo3.html和一个网络示例

I have created a .bash_profile file in my home directory /Users/philhunter/ which sets my classpaths: 我在主目录/ Users / philhunter /中创建了.bash_profile文件,该文件设置了我的类路径:

CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562_Project/lucene-3.0.3/lucene-core-3.0.3.jar
CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562_Project/lucene-3.0.3/lucene-demo-3.0.3.jar
CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562_Project/lucene-3.0.3/src/demo/org/apache/lucene/demo

When i try and run the commands it asks on the command line i am getting ClassDefNotFoundError: 当我尝试运行命令时,它在命令行中询问我正在收到ClassDefNotFoundError:

Exception in thread "main" java.lang.NoClassDefFoundError: /Users/philhunter/Desktop/COM562_Project/lucene-3/0/3/src/demo/org/apache/lucene/demo/IndexHTML
Caused by: java.lang.ClassNotFoundException: .Users.philhunter.Desktop.COM562_Project.lucene-3.0.3.src.demo.org.apache.lucene.demo.IndexHTML
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

The command line command is: 命令行命令是:

java /Users/philhunter/Desktop/COM562_Project/lucene-3.0.3/src/demo/org/apache/lucene/demo/IndexHTML -create -index /Applications/MAMP/htdocs/

which should index my website files. 应该索引我的网站文件。 That indexHTML file is a java file in that last classpath directory above. 该indexHTML文件是上面最后一个类路径目录中的一个java文件。 Anyone know why I am getting theat error!? 任何人都知道为什么我会收到theat错误!

I think the path you're passing is the problem. 我认为您所走的路是问题。 Try adding the following to your bash script 尝试将以下内容添加到您的bash脚本中

cd /Users/philhunter/Desktop/COM562_Project/lucene-3.0.3/src/demo/
java org.apache.lucene.demo.IndexHTML -create -index /Applications/MAMP/htdocs/

The problem is that when you run 问题是当您运行时

java /Users/philhunter/Desktop/COM562_Project/lucene-3.0.3/src/demo/org/apache/lucene/demo/IndexHTML

you are telling java run the class in the package 您正在告诉Java运行包中的类

Users.philhunter.Desktop.COM562_Project.lucene-3.0.3.src.demo.org.apache.lucene.demo
.

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

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