javaluceneh2classnotfoundexceptionclassnotfound

Class "org.h2.fulltext.FullTextLucene" not found - H2 database 1.4.* does not work with Lucene Core 4.*


I have written a small Java tool, but I still get the same error that a class can not be found

Class "org.h2.fulltext.FullTextLucene" not found; SQL statement:
CREATE ALIAS IF NOT EXISTS FTL_INIT FOR
"org.h2.fulltext.FullTextLucene.init"; [ 90086-178]
     at org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
     at org.h2.message.DbException.get(DbException.java:167)
     at org.h2.util.Utils.loadUserClass(Utils.java:676)
     at org.h2.engine.FunctionAlias.loadClass(FunctionAlias.java:146)
     at org.h2.engine.FunctionAlias.load(FunctionAlias.java:122)
     at org.h2.engine.FunctionAlias.init(FunctionAlias.java:107)
     at org.h2.engine.FunctionAlias.newInstance(FunctionAlias.java:78)
     at org.h2.command.ddl.CreateFunctionAlias.update(CreateFunctionAlias.java:50)
     at org.h2.command.CommandContainer.update(CommandContainer.java:79)
     at org.h2.command.Command.executeUpdate(Command.java:254)
     at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:186)
     at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:160)
     at database.main(database.java:30) Caused by: java.lang.NoClassDefFoundError: org/apache/lucene/analysis/standard/StandardAnalyzer
     at java.lang.Class.forName0(Native Method)
     at java.lang.Class.forName(Class.java:190)
     at org.h2.util.Utils.loadUserClass(Utils.java:665)
     ... 10 more Caused by: java.lang.ClassNotFoundException: org.apache.lucene.analysis.standard .StandardAnalyzer
     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:425)
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
     ... 13 more

Which version of Lucene Core works with H2 1.4.x? I thought that I need Lucene Core 4.x because:


Solution

  • H2 definitely doesn't support Lucene 4.x. Looking at the 1.4.178 source for org.h2.fulltext.FullTextLucene reveals a class definitely designed to work with Lucene 3.x (targeting Lucene 3.0 functionality, specifically).