我在Mac上设置classpath时遇到问题。以下是我尝试过的代码,
首先我使用终端
导出了罐子abc-MacBook-Pro:~ abc$ export
CLASSPATH=$CLASSPATH:/Users/abc/Desktop/IR/luceneJar/demo/lucene-demo-4.0.0.jar: export
CLASSPATH=$CLASSPATH:/Users/abc/Desktop/IR/luceneJar/core/lucene-core-4.0.0.jar: export
CLASSPATH=$CLASSPATH:/Users/abc/Desktop/IR/luceneJar/queryparser/lucene-queryparser-4.0.0.jar: export
CLASSPATH=$CLASSPATH:/Users/abc/Desktop/IR/luceneJar/analysis/common/lucene-analyzers-common-4.0.0.jar
然后当我回显类路径时,结果如下
abc-MacBook-Pro:~ abc$ echo $CLASSPATH
/Users/abc/Desktop/IR/lucene-4.0.0 2/core/lucene-core 4.0.0.jar:
/Users/abc/Desktop/IR/lucene-4.0.0 2/demo/lucene-demo-4.0.0.jar:
/Users/abc/Desktop/IR/luceneJar/analysis/common/lucene-analyzers-common-4.0.0.jar
当我尝试使用索引文件时,我遇到的错误是
abc-MacBook-Pro:~ abc$ 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)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
请让我知道上述错误,谢谢你提前。我是Lucene Java的新手。
答案 0 :(得分:0)
这是常见的Java类路径问题,这里没有与lucene(或mac)相关的内容。
试试这个
1) Create lib folder and move all your lucene jars to lib
- lets say your project has two folders now lib and src, lib has all jars and src has yourJavaFile.java
2) Run below commands for compilation and execution from your src
- javac -cp ".:../lib/*" yourJavaFile.java
- java -cp ".:../lib/*" yourJavaFile