2

I have written a program which uses Lucene to text match addresses for a scraper. Everything works fine in NetBeans when it's compiled and run, however when built and run from the command line, I receive the following:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/index/IndexableField
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)

I've found that the class IndexableField.class is not in any of the jar files so I have no idea why it works in the first place, let alone why it doesn't work once it's built and run from the Terminal.

3
  • do you have any lucene related jars hidden somewhere? running a java app in IDE like NetBeans or Eclipse is simple cuz Classpath is figured out by IDE automatically. So basically two things you need to do. 1. search for jars like lucene-*.jar; 2. when you run the app through command line, you need to set up class path first javac -cp Feb 18, 2013 at 2:24
  • Command line may have different class path with the NetBeans, IndexableField.class should be in the Lucene-core.jar.
    – Joe
    Feb 18, 2013 at 2:25
  • Cheers guys. IndexableField was for some reason not in the core jar. Have downloaded the precompiled version (I'd been building from source) and it works fine now.
    – C Dawson
    Feb 18, 2013 at 3:28

1 Answer 1

0

I met with the problem. According to Lucene docs I add 4 Jars into classpath and solved problem. Below is from the docs.

"Setting your CLASSPATH

First, you should download the latest Lucene distribution and then extract it to a working directory.

You need four JARs: the Lucene JAR, the queryparser JAR, the common analysis JAR, and the Lucene demo JAR. You should see the Lucene JAR file in the core/ directory you created when you extracted the archive -- it should be named something like lucene-core-{version}.jar. You should also see files called lucene-queryparser-{version}.jar, lucene-analyzers-common-{version}.jar and lucene-demo-{version}.jar under queryparser, analysis/common/ and demo/, respectively.

Put all four of these files in your Java CLASSPATH."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.