0

I am trying to read a N-Triples (.nt) DBpedia file with NxParser, but I had the following error, and I don't know what to do.

Exception in thread "main" java.lang.NoClassDefFoundError: org/semanticweb/yars/nx/parser/NxParser$1
    at org.semanticweb.yars.nx.parser.NxParser.stringItFromBufferedReader(Unknown Source)
    at org.semanticweb.yars.nx.parser.NxParser.<init>(Unknown Source)
    at org.semanticweb.yars.nx.parser.NxParser.<init>(Unknown Source)
    at SentencesMatching_prova.main(SentencesMatching_prova.java:29)
Caused by: java.lang.ClassNotFoundException: org.semanticweb.yars.nx.parser.NxParser$1
    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:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 4 more

The source code of the script is:

import java.io.*;
import org.semanticweb.yars.nx.parser.*;

public class SentencesMatching_prova {
  public static void main(String[] args) {
    try {
      String relationFileName = "../zzz-trash/revisions_en.nt";
      FileInputStream is = new FileInputStream(relationFileName);
      NxParser nxp = new NxParser(is);
      while (nxp.hasNext()) {
        // do stuff
      }
    } catch (Exception ex) {
      ex.printStackTrace(System.out);
    }
  }
}
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • Is `NxParser` related jar file added in your classpath.? – RanRag Feb 10 '12 at 10:17
  • Yes, I downloaded version 1.2.1 because I have Java 6. I downloaded from http://code.google.com/p/nxparser/downloads/list – Alessio Palmero Aprosio Feb 10 '12 at 10:31
  • The `javac` went ok, so I think classpath is ok too... – Alessio Palmero Aprosio Feb 10 '12 at 10:32
  • I tried to remove classpath and `javac` failed, so I think it is correct. – Alessio Palmero Aprosio Feb 10 '12 at 10:33
  • I launched `javac -cp .:../jbin/:../lib/nxparser-1.2.1-lite.jar -d ../jbin/ ../src/SentencesMatching_prova.java` and then `java -cp .:../jbin/:../lib/nxparser-1.2.1-lite.jar -Xmx4g -Dfile.encoding=UTF-8 SentencesMatching_prova`. I use different folders for libs, sources and bin, it usually works. – Alessio Palmero Aprosio Feb 10 '12 at 10:40
  • Try this `javac -cp ../jbin/:../lib/nxparser-1.2.1-lite.jar -d ../jbin/ ../src/SentencesMatching_prova.java` – RanRag Feb 10 '12 at 11:20
  • You do realize that adding the class path for compilation doesn't magically add those libraries when you later run the compiled code? You also have to specify the class path when you run `java` to actually run your code. The error you are getting means those libraries aren't on the class path when you are running the code – RobV Feb 10 '12 at 16:43
  • Yes, but I use the `-cp` command when I use `java`, too. I always did in that way and it worked for all other scripts. I cannot understand what is different now. I tried in Linux and Mac, and the error is the same. I can send you the zipped folder, so that you can try with the same files I have. – Alessio Palmero Aprosio Feb 11 '12 at 00:18
  • Yes you can, your command will be something like `java -cp .:/lib mypackage.myclass` - you state the class path and then the name of the class you wish to run. Or for a JAR file `java -cp .:/lib -jar myjar.jar` (assuming the JAR defines a default main class – RobV Feb 11 '12 at 05:23
  • Solved! The problem was in the "lite" version of NxParser 1.2.1, as it doesn't have the `NxParser$1` file in the jar. I'm using the non-lite version and it works. I think it is a bug in the 1.2.1 release of NxParser. – Alessio Palmero Aprosio Mar 01 '12 at 16:14
  • @AlessioPalmeroAprosio You should [post your result as an answer](http://meta.stackexchange.com/q/54718/225437) and accept it so that this isn't an "unanswered question". After all, you found the solution. – Joshua Taylor Jun 27 '13 at 21:33

0 Answers0