Hi我想在终端中编译java代码我在终端中输入以下命令
javac -cp .:../../lucene-8.6.3/lucene-8.6.3/core/lucene-core-8.6.3.jar:../../lucene-8.6.3/lucene-8.6.3/analysis/common/lucene-analyzers-common-8.6.3.jar:../../lucene-8.6.3/lucene-8.6.3/queryparser/lucene-queryparser-8.6.3.jar IndexFiles.java
我没有得到任何错误,在我输入以下命令后运行:
java -cp .:../../lucene-8.6.3/lucene-8.6.3/core/lucene-core-8.6.3.jar:../../lucene-8.6.3/lucene-8.6.3/analysis/common/lucene-analyzers-common-8.6.3.jar:../../lucene-8.6.3/lucene-8.6.3/queryparser/lucene-queryparser-8.6.3.jar IndexFiles
但我得到了这个错误:
Error: Could not find or load main class IndexFiles
Caused by: java.lang.NoClassDefFoundError: lucene/IndexFiles (wrong name: IndexFiles)
我该怎么办?我怎么了?
这是IndexFiles类
package lucene;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.*;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Date;
/** Index all text files under a directory.
* <p>
* This is a command-line application demonstrating simple Lucene indexing.
* Run it with no command-line arguments for usage information.
*/
public class IndexFiles {
....
由于您的类在包lucene
中,这是您需要传递给java
的类名:它需要完全限定名。
CLASSPATH=../../lucene-8.6.3/lucene-8.6.3/core/lucene-core-8.6.3.jar:../../lucene-8.6.3/lucene-8.6.3/analysis/common/lucene-analyzers-common-8.6.3.jar:../../lucene-8.6.3/lucene-8.6.3/queryparser/lucene-queryparser-8.6.3.jar
java -cp ".:$CLASSPATH" lucene.IndexFiles
您还需要确保.class
文件实际上位于正确的位置。在您的情况下,这将是./lucene/IndexFiles.class
。