2

好吧,当我运行我的代码时,我得到了这些异常,这是代码

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
4

2 回答 2

0

下载 commons logging http://mirrors.cnnic.cn/apache//commons/logging/binaries/commons-logging-1.1.3-bin.zip并将 jar 添加到您的类路径中。

于 2013-06-25T09:29:00.507 回答
0

您似乎缺少类路径中的 commons-logging jar。您可以从这里下载相关版本的 jar:

http://commons.apache.org/proper/commons-logging/download_logging.cgi

在类路径中添加这个 jar 并测试

于 2013-06-25T09:29:31.163 回答