javamavenrdfr2rml

main class exception when running db2triples for the first time


I'm trying to use db2triples for the first time, which is a java / maven project.

I got information about it from its github page.

So far, I have performed the following steps:

  1. cd /programs/db2triples-master
  2. vim pom.xml and added the db2triples dependency
  3. mvn compile
  4. mvn package
  5. mvn dependency:copy-dependencies
  6. java -cp target/dependency/*.jar:target/db2triples-1.0.3-SNAPSHOT.jar net.antidot.semantic.rdf.rdb2rdf.main.Db2triples

And I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3040)
    at java.lang.Class.getMethod0(Class.java:3010)
    at java.lang.Class.getMethod(Class.java:1776)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli.ParseException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

After googling around, this may be a classpath error, but I'm not sure. What needs to be done in order to run this application?


Solution

  • The error means that when you run db2triples, it can't find a dependency that is needed.

    One way to resolve this problem is to add the required dependencies to your class path. Is the apache commons cli jar actually sitting in target/dependencies?

    Another way to resolve this is to build a jar that has all the dependencies embedded. The assembly plugin as a jar-with-dependencies descriptor. Add this to your <build><plugins> section in your pom.

      <plugin>
         <artifactId>maven-assembly-plugin</artifactId>
         <version>2.5.3</version>
         <configuration>
            <descriptorId>jar-with-dependencies</descriptorId>   
         </configuration>
      </plugin>
    

    To build it mvn assembly:assembly.

    You should have another jar sitting in targets named something like db2triples-<version>-jar-with-dependencies.jar. Then to run the application, you just need to run java -cp dbp2triples-<version>-jar-with-dependencies.jar net.antidot.semantic.rdf.rdb2rdf.main.Db2triples