2

I am new to java and have used it in netBeans but have never tried to compile or run it from terminal. So, my question may look naive. I have a directory of this structure:

Folder X contains: couple of files and a folder named esa-lucene.

esa-lucene is a directory having three folders src, lib, web:

.classpath, lib, .project, .settings, src, web

and I am trying to run a java file " ESAWikipediaIndexer.java" which exists in this subdirectory:

X/esa-lucene/src/edu/wiki/index/ESAWikipediaIndexer.java

I cd into Folder X and use this:

java -cp esa-lucene.jar edu.wiki.index.ESAWikipediaIndexer

But it gives me this error:

Exception in thread "main" java.lang.NoClassDefFoundError: edu/wiki/index/ESAWikipediaIndexer
Caused by: java.lang.ClassNotFoundException: edu.wiki.index.ESAWikipediaIndexer
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: edu.wiki.index.ESAWikipediaIndexer. Program will exit.

also I've checked .classpath and it contains:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="lib" path="lib/servlet-api.jar"/>
    <classpathentry kind="lib" path="web/WEB-INF/lib/lucene-analyzers-3.0.0.jar"/>
    <classpathentry kind="lib" path="web/WEB-INF/lib/lucene-core-3.0.0.jar"/>
    <classpathentry kind="lib" path="web/WEB-INF/lib/mysql-connector-java-5.1.12-bin.jar"/>
    <classpathentry kind="lib" path="web/WEB-INF/lib/trove-2.1.0.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

I've checked the lib and web/WEB-INF/lib/ folders as well and all the required external libraries (jar files) also exist in this folder.

I searched to find any solution and tried a couple of things but none of them worked. Have no clue how to make it work!

BTW, apparently people have used this package before, and I just downloaded to use it too but wasn't successful so far.

Toolsa
  • 23
  • 3
  • have you tried : java -cp esa-lucene.jar:. – scrappedcola Sep 17 '12 at 21:48
  • I just tried java -cp esa-lucene.jar:. edu.wiki.index.ESAWikipediaIndexer and it gives me the same error. – Toolsa Sep 17 '12 at 21:52
  • http://stackoverflow.com/questions/219585/setting-multiple-jars-in-java-classpath http://stackoverflow.com/questions/9053146/set-folder-for-classpath-in-java – Alvin Pradeep Sep 17 '12 at 21:55
  • @Alvin - If I understand the NoClassDefFoundError correctly, I don't think that the problem is about finding external libraries. I guess, I am not calling the mentioned java file properly. – Toolsa Sep 17 '12 at 22:01
  • 1
    Yeah, 9 times out of 10 (of not 10 of 10), NoClassDefFoundError indicates some sort of problem with your jar search path. This can either be a class missing altogether, or a version mismatch of some sort. In this case it looks like a class is just plain missing (though sometimes "ClassNotFoundException" can be deceptive). – Hot Licks Sep 17 '12 at 22:24

2 Answers2

0

Looks like you are referring to Eclipse classpath and .project files. That being the case why dont you try running it in eclipse.

However since here you are running it manually the classpath entries in classpath file are not being used. Also can you tell us where the .class file for the ESAWikipediaIndexer.java. If you run the below command

java -cp */esa-lucene.jar edu.wiki.index.ESAWikipediaIndexer

From the directory where it is located, it should work. Also you need to provide full path or relative path to esa-lucene.jar in the above command.

sharadendu sinha
  • 844
  • 4
  • 10
  • When I try to compile ESAWikipediaIndexer manually it gives me this error: ESAWikipediaIndexer.java:114: cannot find symbol symbol : class WikipediaAnalyzer location: class edu.wiki.index.ESAWikipediaIndexer writer = new IndexWriter(indexDir, new WikipediaAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED); Note: ESAWikipediaIndexer.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. – Toolsa Sep 17 '12 at 22:06
  • is there a bin directory that is being automatically created by eclipse ? – sharadendu sinha Sep 17 '12 at 22:12
  • no. the esa-lucene that I downloaded in detail is available here: https://github.com/faraday/wikiprep-esa/tree/master/esa-lucene – Toolsa Sep 17 '12 at 22:16
  • Try importing your downloaded code basee into eclipse as File->import->Existing projects into workspace. And rpovide the top level directory of your downloaded code. It should work for you. – sharadendu sinha Sep 17 '12 at 22:21
  • I used netBeans and imported it as eclipse project and it worked. Thanks! – Toolsa Sep 17 '12 at 22:32
0

As others have mentioned, you need to make sure the ESAWikipediaIndexer.class file is either in the esa-lucene.jar or in a edu/wiki/index folder structure locatable in the directory you run the java command from. Here's what you can do. look in the jar file to make sure the edu/wiki/index folder structure exists in it. You can use jar -tvf esa-lucene.jar or if you are on windows copy esa-lucene.jar to esa-lucene.zip and double click it to open it up. If that's not where your ESAWikipediaIndexer.class is then it's probably under either the bin, build, classes, or target folder from your project's root. Many IDEs output to something like build/classes. If the class output is there then add build/classes to your classpath in your above command like: java -cp build/classes:esa-lucene.jar edu.wiki.index.ESAWikipediaIndexer on Mac/Linux or java -cp build/classes;esa-lucene.jar edu.wiki.index.ESAWikipediaIndexer on Windows.

Cliff
  • 9,408
  • 6
  • 59
  • 95