I am a Java newbie, in fact the only reason why I am using it, it's because of lucene.
I used eclipse on Windows to develop a lucene application and worked. So now when I try to compile the application from Linux command-line, it doesn't work.
Here is my folder structure.
search_example/
├── lucene-5.0.0
│ ├── analysis
│ │ └── common
│ │ └── lucene-analyzers-common-5.0.0.jar
│ ├── core
│ │ └── lucene-core-5.0.0.jar
│ ├── queries
│ │ └── lucene-queries-5.0.0.jar
│ └── queryparser
│ └── lucene-queryparser-5.0.0.jar
├── lucene_test
│ ├── IndexFiles.java
│ ├── IndexMarkdown.java
│ ├── SearchFiles.java
│ └── SearchMarkdown.java
└── readme.md
And here is the compilation call:
$ cd ~/search_example
$ javac lucene_test/IndexMarkdown.java -classpath ./; lucene-5.0.0/analysis/common/lucene-analyzers-common-5.0.0.jar; lucene-5.0.0/core/lucene-core-5.0.0.jar; lucene-5.0.0/queries/lucene-queries-5.0.0.jar ; lucene-5.0.0/queryparser/lucene-queryparser-5.0.0.jar
which I get the following error, indicating that it cannot find the 'jar' files that I passed in as 'classpath'
./lucene_test/IndexFiles.java:20: error: package org.apache.lucene.analysis does not exist
import org.apache.lucene.analysis.Analyzer;
^
./lucene_test/IndexFiles.java:21: error: package org.apache.lucene.analysis.standard does not exist
import org.apache.lucene.analysis.standard.StandardAnalyzer;
^
./lucene_test/IndexFiles.java:22: error: package org.apache.lucene.document does not exist
import org.apache.lucene.document.Document;
^
./lucene_test/IndexFiles.java:23: error: package org.apache.lucene.document does not exist
import org.apache.lucene.document.Field;
^
./lucene_test/IndexFiles.java:24: error: package org.apache.lucene.document does not exist
import org.apache.lucene.document.LongField;
^
./lucene_test/IndexFiles.java:25: error: package org.apache.lucene.document does not exist
import org.apache.lucene.document.StringField;
^
./lucene_test/IndexFiles.java:26: error: package org.apache.lucene.document does not exist
import org.apache.lucene.document.TextField;
^
./lucene_test/IndexFiles.java:27: error: package org.apache.lucene.index does not exist
import org.apache.lucene.index.IndexWriter;
^
./lucene_test/IndexFiles.java:28: error: package org.apache.lucene.index.IndexWriterConfig does not exist
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
^
./lucene_test/IndexFiles.java:29: error: package org.apache.lucene.index does not exist
import org.apache.lucene.index.IndexWriterConfig;
^
./lucene_test/IndexFiles.java:30: error: package org.apache.lucene.index does not exist
import org.apache.lucene.index.Term;
^
./lucene_test/IndexFiles.java:31: error: package org.apache.lucene.store does not exist
import org.apache.lucene.store.Directory;
^
./lucene_test/IndexFiles.java:32: error: package org.apache.lucene.store does not exist
import org.apache.lucene.store.FSDirectory;
^
./lucene_test/IndexFiles.java:52: error: cannot find symbol
private IndexWriter _writer;
^
symbol: class IndexWriter
location: class IndexFiles
./lucene_test/IndexFiles.java:73: error: cannot find symbol
Directory dir = FSDirectory.open(_indexPathObj);
^
symbol: class Directory
location: class IndexFiles
./lucene_test/IndexFiles.java:73: error: cannot find symbol
Directory dir = FSDirectory.open(_indexPathObj);
^
symbol: variable FSDirectory
location: class IndexFiles
./lucene_test/IndexFiles.java:74: error: cannot find symbol
Analyzer analyzer = new StandardAnalyzer();
^
symbol: class Analyzer
location: class IndexFiles
./lucene_test/IndexFiles.java:74: error: cannot find symbol
Analyzer analyzer = new StandardAnalyzer();
^
symbol: class StandardAnalyzer
location: class IndexFiles
./lucene_test/IndexFiles.java:75: error: cannot find symbol
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
^
symbol: class IndexWriterConfig
location: class IndexFiles
./lucene_test/IndexFiles.java:75: error: cannot find symbol
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
^
symbol: class IndexWriterConfig
location: class IndexFiles
./lucene_test/IndexFiles.java:76: error: cannot find symbol
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
^
symbol: variable OpenMode
location: class IndexFiles
./lucene_test/IndexFiles.java:77: error: cannot find symbol
_writer = new IndexWriter(dir, iwc);
^
symbol: class IndexWriter
location: class IndexFiles
./lucene_test/IndexFiles.java:161: error: cannot find symbol
Document doc = new Document();
^
symbol: class Document
location: class IndexFiles
./lucene_test/IndexFiles.java:161: error: cannot find symbol
Document doc = new Document();
^
symbol: class Document
location: class IndexFiles
./lucene_test/IndexFiles.java:164: error: cannot find symbol
doc.add(new TextField("category", category, Field.Store.YES));
^
symbol: class TextField
location: class IndexFiles
./lucene_test/IndexFiles.java:164: error: package Field does not exist
doc.add(new TextField("category", category, Field.Store.YES));
^
./lucene_test/IndexFiles.java:165: error: cannot find symbol
doc.add(new StringField("subject", subject, Field.Store.YES));
^
symbol: class StringField
location: class IndexFiles
./lucene_test/IndexFiles.java:165: error: package Field does not exist
doc.add(new StringField("subject", subject, Field.Store.YES));
^
./lucene_test/IndexFiles.java:175: error: cannot find symbol
doc.add(new LongField("modified", lastModified, Field.Store.NO));
^
symbol: class LongField
location: class IndexFiles
./lucene_test/IndexFiles.java:175: error: package Field does not exist
doc.add(new LongField("modified", lastModified, Field.Store.NO));
^
./lucene_test/IndexFiles.java:181: error: cannot find symbol
doc.add(new TextField("contents", new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))));
^
symbol: class TextField
location: class IndexFiles
./lucene_test/IndexFiles.java:184: error: cannot find symbol
if (_writer.getConfig().getOpenMode() == OpenMode.CREATE)
^
symbol: variable OpenMode
location: class IndexFiles
./lucene_test/IndexFiles.java:195: error: cannot find symbol
_writer.updateDocument(new Term("path", file.toString()), doc);
^
symbol: class Term
location: class IndexFiles
Since I was compiling on a Linux OS, multiple directories in classpath
should've been separated with a colon(:) not a semi-colon(;). So here is the new complication code which also I included the full path of the jar
files, but it still cannot find the classes defined in those jar files.
javac -classpath ~/search_example/lucene-5.0.0/analysis/common/lucene-analyzers-common-5.0.0.jar:~/search_example/lucene-5.0.0/core/lucene-core-5.0.0.jar:~/search_example/lucene-5.0.0/queries/lucene-queries-5.0.0.jar:~/search_example/lucene-5.0.0/queryparser/lucene-queryparser-5.0.0.jar lucene_test/*.java
Its always good to give full path to your classpath vars or atleast proper reference from your current directory.
However, its always good to use a build tool like maven which helps to get around dependencies and classpaths.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.