简体   繁体   中英

Java Lucene Classpath problems ubuntu

I'm having problems trying to run a Java file that uses Apache Lucene.

I can compile it since I have the .jar file in my classpath but when I want to run the .class file, I have to add this parameter -classpath .:lucene-core.xxjar , if I don't I get this error:

    Exception in thread "main" java.lang.NoClassDefFoundError: HelloLucene
    Caused by: java.lang.ClassNotFoundException: HelloLucene
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    Could not find the main class: HelloLucene.  Program will exit.

Do I have to add the classpath to the jvm also? If so how do I do this?

Here's the output I get when I echo my CLASSPATH:

ricardo@ricardo-laptop:~/Desktop/lucene/Indexer$ echo $CLASSPATH
/home/ricardo/lucene-3.4.0/lucene-core-3.4.0.jar:/home/ricardo/lucene-3.4.0/contrib/demo/lucene-demo-3.4.0.jar

The class that's not found is your class, ie HelloLucene . Not the library.

Your class is probably compiled under bin or target/classes , so your classpath has to point whereever it is, ie

-classpath target/classes:...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM