さて、コードを実行するとこれらの例外が発生します。コードは次のとおりです
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