好吧,当我运行我的代码时,我得到了这些异常,这是代码
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
import org.apache.lucene.store.jdbc.JdbcDirectory;
import org.apache.lucene.store.jdbc.dialect.MySQLDialect;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.io.IOException;
public class kel
{
public static void main(String args[])
{
//code snippet to create index
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUser("root");
dataSource.setPassword("n");
dataSource.setDatabaseName("lol");
dataSource.setEmulateLocators(true); //This is important because we are dealing with a blob type data field
JdbcDirectory jdbcDir = new JdbcDirectory(dataSource, new MySQLDialect(), "ii");
try
{
jdbcDir.create();
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
}
我运行程序时出现以下异常
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.lucene.store.jdbc.support.JdbcTemplate.<clinit>(JdbcTemplate.java:44)
at org.apache.lucene.store.jdbc.JdbcDirectory.initialize(JdbcDirectory.java:162)
at org.apache.lucene.store.jdbc.JdbcDirectory.<init>(JdbcDirectory.java:122)
at kel.main(kel.java:43)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 4 more
答案 0 :(得分:0)
下载记录http://mirrors.cnnic.cn/apache//commons/logging/binaries/commons-logging-1.1.3-bin.zip的公共空间并将jar添加到您的类路径。
答案 1 :(得分:0)
您似乎错过了类路径中的commons-logging jar。您可以从这里下载相关的版本jar:
http://commons.apache.org/proper/commons-logging/download_logging.cgi
在classpath中添加此jar并测试