That doesn't work because only your own classes are in the classpath then.
Options:
1) Add all necessary JAR files from the Jena distribution to the classpath
2) Use the Maven exec plugin from the command line
3) build a fat JAR that also contains the classes of the Maven dependencies
> Hi,
>
> I am trying to do the first example of the jena rdf tutorial.
> It seems that the class is not found even the maven build was successful.
>
> Here is my class code:
>
> package com.mycompany.app;
>
> import org.apache.jena.rdf.model.*;
> import org.apache.jena.vocabulary.*;
>
> public class RdfWriter {
> static String personURI = "http://somewhere/JohnSmith";
> static String fullName = "John Smith";
>
> public static void main(String[] args) {
> // // create an empty model
> Model model = ModelFactory.createDefaultModel();
> // // create the resource
> // Resource johnSmith = model.createResource(personURI);
> // // add the property
> // johnSmith.addProperty(VCARD.FN, fullName);
> System.out.println("this is rdf writer");
> }
>
> }
>
> I am running it like this:
>
> java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.RdfWriter
>
> And here is my pom file:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/maven-v4_0_0.xsd">
> <modelVersion>4.0.0</modelVersion>
> <groupId>com.mycompany.app</groupId>
> <artifactId>my-app</artifactId>
> <packaging>jar</packaging>
> <version>1.0-SNAPSHOT</version>
> <name>my-app</name>
> <url>http://maven.apache.org</url>
>
> <properties>
> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> </properties>
>
> <dependencies>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>3.8.1</version>
> <scope>test</scope>
> </dependency>
> <dependency>
> <groupId>org.apache.jena</groupId>
> <artifactId>apache-jena-libs</artifactId>
> <version>3.1.1</version>
> <type>pom</type>
> </dependency>
> </dependencies>
> </project>
>
> Here is the full error that I get:
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/jena/rdf/model/ModelFactory
> at com.mycompany.app.RdfWriter.main(RdfWriter.java:13)
> Caused by: java.lang.ClassNotFoundException:
> org.apache.jena.rdf.model.ModelFactory
> at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> ... 1 more
>
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center