Saturday 15 January 2011

java - lucene main function not found -



java - lucene main function not found -

i running lucene library text analysis project (i relatively new java). there problem main function (or command).

the lucene version using 3.0.0, , compiled jar file. jar file in same folder main class file indexer.java.

i first run compile code:

javac -cp \lucene-core-3.0.0.jar indexer.java

and worked correctly , created indexer.class file in same directory.

then run same sort of command:

java -cp \lucene-core.3.0.0.jar indexer

this time command line output says don't have main class indexer:

could not find or load main class indexer

i checked original java code, there main method defined:

import org.apache.lucene.index.*; import java.io.ioexception; import java.io.file; import org.apache.lucene.store.directory; import org.apache.lucene.store.fsdirectory; import org.apache.lucene.analysis.standard.*; import org.apache.lucene.util.version; import org.apache.lucene.document.document; import org.apache.lucene.document.field; import java.io.filereader; public class indexer { private indexwriter writer; private void indexfile(file f) throws exception{ system.out.println("indexing " + f.getcanonicalpath()); document doc = getdocument(f); if(doc != null){ writer.adddocument(doc); } } public indexer(string indexdir) throws ioexception{ directory dir = fsdirectory.open(new file(indexdir)); author = new indexwriter(dir,new standardanalyzer(version.lucene_30), true,indexwriter.maxfieldlength.unlimited); } protected document getdocument(file f) throws exception{ document doc = new document(); doc.add(new field("contents", new filereader(f))); doc.add(new field("filename", f.getname(), field.store.yes, field.index.not_analyzed)); doc.add(new field("fullpath", f.getcanonicalpath(), field.store.yes, field.index.not_analyzed)); homecoming doc; } protected boolean acceptfile(file f){ homecoming f.getname().endswith(".txt"); } public int index(string datadir) throws exception{ file[] files = new file(datadir).listfiles(); for(int = 0; < files.length;i++){ file f = files[i]; if(!f.isdirectory() && !f.ishidden() && f.exists() && f.canread() && acceptfile(f)){ indexfile(f); } } homecoming writer.numdocs(); } public void close() throws ioexception{ writer.close(); } public static void main(string[] args) throws exception{ if(args.length != 2){ throw new exception("usage: java " + indexer.class.getname()+" <index dir><data dir"); } string indexdir = args[0]; string datadir = args[1]; long start = system.currenttimemillis(); indexer indexer = new indexer(indexdir); int numindexed = indexer.index(datadir); indexer.close(); long end = system.currenttimemillis(); system.out.println("indexing " + numindexed + " files took " + (end-start)+ " milliseconds."); } }

what wrong code/command?

the jvm doesn't include current directory in runtime classpath when 1 explicitly specified. try

java -cp ".:lucene-core.3.0.0.jar" indexer

java lucene

No comments:

Post a Comment