Discussion:
JENAROOT or CLASSPATH Issue
Cumulative Knowledge
2018-04-21 19:53:25 UTC
Permalink
I'm getting Apache Jena set up and am having some issues. I think my issue
is with environment variable, but I'm not sure.

Here is what I've posted on Stack Overflow:

Based on this tutorial
<http://staff.um.edu.mt/cabe2/lectures/webscience/docs/jena.pdf> I've
gotten my workspace set up. I've removed the package identifier from my code
<https://stackoverflow.com/questions/36402759/error-could-not-find-or-load-main-class-classdemo>
.

Now I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/jena/rdf/model/ModelFactory at
Tutorial01.main(Tutorial01.java:34)
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)

I think it's a JENAROOT Issue. I think I'm setting it and adding it
<https://stackoverflow.com/questions/28177971/tdbloader2-fails-with-classpath-error/28181902#28181902>
to the path correctly. It's also mentioned here
<https://jena.apache.org/documentation/tools/>, but I haven't been able to
troubleshoot it yet.

Anybody can point me in the right direction?
Thanks,
Louis
Andy Seaborne
2018-04-22 08:42:15 UTC
Permalink
Louis,

The exception means that the classpth does not contain the jena-core
jar. Put all the jars from the distribution lib directory in the
classpath. Nowadays in java you can put '...\lib\*' on the classpath and
it will include all the jars in that directory.

See the bat scripts in the download or
https://github.com/apache/jena/tree/master/apache-jena/bat

then print out the classpath to make sure it is right.

Andy
Post by Cumulative Knowledge
I'm getting Apache Jena set up and am having some issues. I think my issue
is with environment variable, but I'm not sure.
Based on this tutorial
<http://staff.um.edu.mt/cabe2/lectures/webscience/docs/jena.pdf> I've
gotten my workspace set up. I've removed the package identifier from my code
The way to call main is to use it's full name, package included:

java -cp ... <fullname>

java -cp ... a.b.C

where C has the static main method
Post by Cumulative Knowledge
<https://stackoverflow.com/questions/36402759/error-could-not-find-or-load-main-class-classdemo>
.
org/apache/jena/rdf/model/ModelFactory at
Tutorial01.main(Tutorial01.java:34)
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)
I think it's a JENAROOT Issue. I think I'm setting it and adding it
<https://stackoverflow.com/questions/28177971/tdbloader2-fails-with-classpath-error/28181902#28181902>
to the path correctly. It's also mentioned here
<https://jena.apache.org/documentation/tools/>, but I haven't been able to
troubleshoot it yet.
Anybody can point me in the right direction?
Thanks,
Louis
Cumulative Knowledge
2018-04-22 18:28:52 UTC
Permalink
Hi Andy,

Thanks for the help. I'm still getting the same error. Right now I
have JENAROOT and JENA_HOME set to the same path.

I added classpath like so:
$ export CLASSPATH=$CLASSPATH:$JENA_HOME/lib/*

Here is what my current classpath:
$ echo $CLASSPATH
/Users/username/Documents/jena/apachejena370/lib/collection-0.7.jar
/Users/username/Documents/jena/apachejena370/lib/commons-cli-1.4.jar
/Users/username/Documents/jena/apachejena370/lib/commons-codec-1.11.jar
/Users/username/Documents/jena/apachejena370/lib/commons-csv-1.5.jar
/Users/username/Documents/jena/apachejena370/lib/commons-io-2.6.jar
/Users/username/Documents/jena/apachejena370/lib/commons-lang3-3.4.jar
/Users/username/Documents/jena/apachejena370/lib/httpclient-4.5.3.jar
/Users/username/Documents/jena/apachejena370/lib/httpclient-cache-4.5.3.jar
/Users/username/Documents/jena/apachejena370/lib/httpcore-4.4.6.jar
/Users/username/Documents/jena/apachejena370/lib/jackson-annotations-2.9.0.jar
/Users/username/Documents/jena/apachejena370/lib/jackson-core-2.9.0.jar
/Users/username/Documents/jena/apachejena370/lib/jackson-databind-2.9.0.jar
/Users/username/Documents/jena/apachejena370/lib/jcl-over-slf4j-1.7.25.jar
/Users/username/Documents/jena/apachejena370/lib/jena-arq-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-base-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-cmds-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-core-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-base-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-index-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-trans-data-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-transaction-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-iri-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-rdfconnection-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-shaded-guava-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-tdb-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-tdb2-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jsonld-java-0.11.1.jar
/Users/username/Documents/jena/apachejena370/lib/libthrift-0.10.0.jar
/Users/username/Documents/jena/apachejena370/lib/log4j-1.2.17.jar
/Users/username/Documents/jena/apachejena370/lib/slf4j-api-1.7.25.jar
/Users/username/Documents/jena/apachejena370/lib/slf4j-log4j12-1.7.25.jar
/Users/username/Documents/jena/apachejena370/lib/xercesImpl-2.11.0.jar
/Users/username/Documents/jena/apachejena370/lib/xml-apis-1.4.01.jar


Any thoughts?

Thanks,
Louis
Post by Andy Seaborne
Louis,
The exception means that the classpth does not contain the jena-core jar.
Put all the jars from the distribution lib directory in the classpath.
Nowadays in java you can put '...\lib\*' on the classpath and it will
include all the jars in that directory.
See the bat scripts in the download or
https://github.com/apache/jena/tree/master/apache-jena/bat
then print out the classpath to make sure it is right.
Andy
Post by Cumulative Knowledge
I'm getting Apache Jena set up and am having some issues. I think my issue
is with environment variable, but I'm not sure.
Based on this tutorial
<http://staff.um.edu.mt/cabe2/lectures/webscience/docs/jena.pdf> I've
gotten my workspace set up. I've removed the package identifier from my code
java -cp ... <fullname>
java -cp ... a.b.C
where C has the static main method
<https://stackoverflow.com/questions/36402759/error-could-
Post by Cumulative Knowledge
not-find-or-load-main-class-classdemo>
.
org/apache/jena/rdf/model/ModelFactory at
Tutorial01.main(Tutorial01.java:34)
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)
I think it's a JENAROOT Issue. I think I'm setting it and adding it
<https://stackoverflow.com/questions/28177971/tdbloader2-fai
ls-with-classpath-error/28181902#28181902>
to the path correctly. It's also mentioned here
<https://jena.apache.org/documentation/tools/>, but I haven't been able to
troubleshoot it yet.
Anybody can point me in the right direction?
Thanks,
Louis
Andy Seaborne
2018-04-22 19:49:38 UTC
Permalink
Post by Cumulative Knowledge
Hi Andy,
Thanks for the help. I'm still getting the same error. Right now I
have JENAROOT and JENA_HOME set to the same path.
$ export CLASSPATH=$CLASSPATH:$JENA_HOME/lib/*
You need to escape the * to stop it be shell expansion. The * needs to
be passed to java.

export CLASSPATH=$CLASSPATH:$JENA_HOME/lib/\*
Post by Cumulative Knowledge
$ echo $CLASSPATH
This does not agree with the line above - no ":" after whatever
$CLASSPATH was before the export.
Post by Cumulative Knowledge
/Users/username/Documents/jena/apachejena370/lib/collection-0.7.jar
/Users/username/Documents/jena/apachejena370/lib/commons-cli-1.4.jar
/Users/username/Documents/jena/apachejena370/lib/commons-codec-1.11.jar
/Users/username/Documents/jena/apachejena370/lib/commons-csv-1.5.jar
/Users/username/Documents/jena/apachejena370/lib/commons-io-2.6.jar
/Users/username/Documents/jena/apachejena370/lib/commons-lang3-3.4.jar
/Users/username/Documents/jena/apachejena370/lib/httpclient-4.5.3.jar
/Users/username/Documents/jena/apachejena370/lib/httpclient-cache-4.5.3.jar
/Users/username/Documents/jena/apachejena370/lib/httpcore-4.4.6.jar
/Users/username/Documents/jena/apachejena370/lib/jackson-annotations-2.9.0.jar
/Users/username/Documents/jena/apachejena370/lib/jackson-core-2.9.0.jar
/Users/username/Documents/jena/apachejena370/lib/jackson-databind-2.9.0.jar
/Users/username/Documents/jena/apachejena370/lib/jcl-over-slf4j-1.7.25.jar
/Users/username/Documents/jena/apachejena370/lib/jena-arq-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-base-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-cmds-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-core-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-base-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-index-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-trans-data-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-transaction-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-iri-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-rdfconnection-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-shaded-guava-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-tdb-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-tdb2-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jsonld-java-0.11.1.jar
/Users/username/Documents/jena/apachejena370/lib/libthrift-0.10.0.jar
/Users/username/Documents/jena/apachejena370/lib/log4j-1.2.17.jar
/Users/username/Documents/jena/apachejena370/lib/slf4j-api-1.7.25.jar
/Users/username/Documents/jena/apachejena370/lib/slf4j-log4j12-1.7.25.jar
/Users/username/Documents/jena/apachejena370/lib/xercesImpl-2.11.0.jar
/Users/username/Documents/jena/apachejena370/lib/xml-apis-1.4.01.jar
Any thoughts?
Thanks,
Louis
Post by Andy Seaborne
Louis,
The exception means that the classpth does not contain the jena-core jar.
Put all the jars from the distribution lib directory in the classpath.
Nowadays in java you can put '...\lib\*' on the classpath and it will
include all the jars in that directory.
See the bat scripts in the download or
https://github.com/apache/jena/tree/master/apache-jena/bat
then print out the classpath to make sure it is right.
Andy
Post by Cumulative Knowledge
I'm getting Apache Jena set up and am having some issues. I think my issue
is with environment variable, but I'm not sure.
Based on this tutorial
<http://staff.um.edu.mt/cabe2/lectures/webscience/docs/jena.pdf> I've
gotten my workspace set up. I've removed the package identifier from my code
java -cp ... <fullname>
java -cp ... a.b.C
where C has the static main method
<https://stackoverflow.com/questions/36402759/error-could-
Post by Cumulative Knowledge
not-find-or-load-main-class-classdemo>
.
org/apache/jena/rdf/model/ModelFactory at
Tutorial01.main(Tutorial01.java:34)
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)
I think it's a JENAROOT Issue. I think I'm setting it and adding it
<https://stackoverflow.com/questions/28177971/tdbloader2-fai
ls-with-classpath-error/28181902#28181902>
to the path correctly. It's also mentioned here
<https://jena.apache.org/documentation/tools/>, but I haven't been able to
troubleshoot it yet.
Anybody can point me in the right direction?
Thanks,
Louis
Cumulative Knowledge
2018-04-22 22:03:37 UTC
Permalink
I think I must be getting closer, but I'm still getting the same error. Now
that I'm escaping the *, the path seems correct.

Here are my current environmental variable settings:

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home

$JENA_HOME
/Users/username/Documents/jena/apachejena370

echo $JENAROOT
/Users/username/Documents/jena/apachejena370

$ echo $CLASSPATH
/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/bin:/Users/
username/Documents/jena/apachejena370/lib/*

When I run the code:

$ sudo java Tutorial01
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/jena/rdf/model/ModelFactory
at Tutorial01.main(Tutorial01.java:34)
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


I've also somehow broken something because javac is no longer working:
$ sudo javac Tutorial01.java

Tutorial01.java:21: error: package org.apache.jena.rdf.model does not exist
import org.apache.jena.rdf.model.*;
^
Tutorial01.java:22: error: package org.apache.jena.vocabulary does not exist
import org.apache.jena.vocabulary.*;
^
Tutorial01.java:34: error: cannot find symbol
Model model = ModelFactory.createDefaultModel();
^
symbol: class Model
location: class Tutorial01
Tutorial01.java:34: error: cannot find symbol
Model model = ModelFactory.createDefaultModel();
^
symbol: variable ModelFactory
location: class Tutorial01
Tutorial01.java:37: error: cannot find symbol
Resource johnSmith = model.createResource(personURI);
^
symbol: class Resource
location: class Tutorial01
Tutorial01.java:40: error: cannot find symbol
johnSmith.addProperty(VCARD.FN, fullName);
^
symbol: variable VCARD
location: class Tutorial01
6 errors
Post by Cumulative Knowledge
Hi Andy,
Thanks for the help. I'm still getting the same error. Right now I
have JENAROOT and JENA_HOME set to the same path.
$ export CLASSPATH=$CLASSPATH:$JENA_HOME/lib/*
You need to escape the * to stop it be shell expansion. The * needs to be
passed to java.
export CLASSPATH=$CLASSPATH:$JENA_HOME/lib/\*
Post by Cumulative Knowledge
$ echo $CLASSPATH
This does not agree with the line above - no ":" after whatever $CLASSPATH
was before the export.
/Users/username/Documents/jena/apachejena370/lib/collection-0.7.jar
Post by Cumulative Knowledge
/Users/username/Documents/jena/apachejena370/lib/commons-cli-1.4.jar
/Users/username/Documents/jena/apachejena370/lib/commons-codec-1.11.jar
/Users/username/Documents/jena/apachejena370/lib/commons-csv-1.5.jar
/Users/username/Documents/jena/apachejena370/lib/commons-io-2.6.jar
/Users/username/Documents/jena/apachejena370/lib/commons-lang3-3.4.jar
/Users/username/Documents/jena/apachejena370/lib/httpclient-4.5.3.jar
/Users/username/Documents/jena/apachejena370/lib/httpclient-
cache-4.5.3.jar
/Users/username/Documents/jena/apachejena370/lib/httpcore-4.4.6.jar
/Users/username/Documents/jena/apachejena370/lib/jackson-
annotations-2.9.0.jar
/Users/username/Documents/jena/apachejena370/lib/jackson-core-2.9.0.jar
/Users/username/Documents/jena/apachejena370/lib/jackson-
databind-2.9.0.jar
/Users/username/Documents/jena/apachejena370/lib/jcl-over-
slf4j-1.7.25.jar
/Users/username/Documents/jena/apachejena370/lib/jena-arq-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-base-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-cmds-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-core-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-base-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-
index-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-
trans-data-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-
transaction-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-iri-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-rdfcon
nection-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-shaded
-guava-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-tdb-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-tdb2-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jsonld-java-0.11.1.jar
/Users/username/Documents/jena/apachejena370/lib/libthrift-0.10.0.jar
/Users/username/Documents/jena/apachejena370/lib/log4j-1.2.17.jar
/Users/username/Documents/jena/apachejena370/lib/slf4j-api-1.7.25.jar
/Users/username/Documents/jena/apachejena370/lib/slf4j-log4j12-1.7.25.jar
/Users/username/Documents/jena/apachejena370/lib/xercesImpl-2.11.0.jar
/Users/username/Documents/jena/apachejena370/lib/xml-apis-1.4.01.jar
Any thoughts?
Thanks,
Louis
Louis,
Post by Andy Seaborne
The exception means that the classpth does not contain the jena-core jar.
Put all the jars from the distribution lib directory in the classpath.
Nowadays in java you can put '...\lib\*' on the classpath and it will
include all the jars in that directory.
See the bat scripts in the download or
https://github.com/apache/jena/tree/master/apache-jena/bat
then print out the classpath to make sure it is right.
Andy
I'm getting Apache Jena set up and am having some issues. I think my
Post by Cumulative Knowledge
issue
is with environment variable, but I'm not sure.
Based on this tutorial
<http://staff.um.edu.mt/cabe2/lectures/webscience/docs/jena.pdf> I've
gotten my workspace set up. I've removed the package identifier from my code
java -cp ... <fullname>
java -cp ... a.b.C
where C has the static main method
<https://stackoverflow.com/questions/36402759/error-could-
Post by Cumulative Knowledge
not-find-or-load-main-class-classdemo>
.
org/apache/jena/rdf/model/ModelFactory at
Tutorial01.main(Tutorial01.java:34)
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)
I think it's a JENAROOT Issue. I think I'm setting it and adding it
<https://stackoverflow.com/questions/28177971/tdbloader2-fai
ls-with-classpath-error/28181902#28181902>
to the path correctly. It's also mentioned here
<https://jena.apache.org/documentation/tools/>, but I haven't been able to
troubleshoot it yet.
Anybody can point me in the right direction?
Thanks,
Louis
Cumulative Knowledge
2018-04-22 18:51:33 UTC
Permalink
I've been trying a few different things that produce different results.
Thought this information might be helpful.

$ java Tutorial01
Error: Could not find or load main class Tutorial01

$ java -cp "$JENA_HOME/lib/*:" Tutorial01
log4j:WARN No appenders could be found for logger (Jena).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
more info.

$ sudo java Tutorial01
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/jena/rdf/model/ModelFactory
at Tutorial01.main(Tutorial01.java:34)
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


$ sudo java -cp "$JENA_HOME/lib/*:" Tutorial01
log4j:WARN No appenders could be found for logger (Jena).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
more info.
Post by Andy Seaborne
Louis,
The exception means that the classpth does not contain the jena-core jar.
Put all the jars from the distribution lib directory in the classpath.
Nowadays in java you can put '...\lib\*' on the classpath and it will
include all the jars in that directory.
See the bat scripts in the download or
https://github.com/apache/jena/tree/master/apache-jena/bat
then print out the classpath to make sure it is right.
Andy
Post by Cumulative Knowledge
I'm getting Apache Jena set up and am having some issues. I think my issue
is with environment variable, but I'm not sure.
Based on this tutorial
<http://staff.um.edu.mt/cabe2/lectures/webscience/docs/jena.pdf> I've
gotten my workspace set up. I've removed the package identifier from my code
java -cp ... <fullname>
java -cp ... a.b.C
where C has the static main method
<https://stackoverflow.com/questions/36402759/error-could-
Post by Cumulative Knowledge
not-find-or-load-main-class-classdemo>
.
org/apache/jena/rdf/model/ModelFactory at
Tutorial01.main(Tutorial01.java:34)
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)
I think it's a JENAROOT Issue. I think I'm setting it and adding it
<https://stackoverflow.com/questions/28177971/tdbloader2-fai
ls-with-classpath-error/28181902#28181902>
to the path correctly. It's also mentioned here
<https://jena.apache.org/documentation/tools/>, but I haven't been able to
troubleshoot it yet.
Anybody can point me in the right direction?
Thanks,
Louis
Andy Seaborne
2018-04-22 19:50:56 UTC
Permalink
Post by Cumulative Knowledge
I've been trying a few different things that produce different results.
Thought this information might be helpful.
$ java Tutorial01
Error: Could not find or load main class Tutorial01
$ java -cp "$JENA_HOME/lib/*:" Tutorial01
log4j:WARN No appenders could be found for logger (Jena).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
more info.
see various questions stackoverflow. They are just warnings.
Post by Cumulative Knowledge
$ sudo java Tutorial01
org/apache/jena/rdf/model/ModelFactory
at Tutorial01.main(Tutorial01.java:34)
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
$ sudo java -cp "$JENA_HOME/lib/*:" Tutorial01
log4j:WARN No appenders could be found for logger (Jena).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
more info.
Post by Andy Seaborne
Louis,
The exception means that the classpth does not contain the jena-core jar.
Put all the jars from the distribution lib directory in the classpath.
Nowadays in java you can put '...\lib\*' on the classpath and it will
include all the jars in that directory.
See the bat scripts in the download or
https://github.com/apache/jena/tree/master/apache-jena/bat
then print out the classpath to make sure it is right.
Andy
Post by Cumulative Knowledge
I'm getting Apache Jena set up and am having some issues. I think my issue
is with environment variable, but I'm not sure.
Based on this tutorial
<http://staff.um.edu.mt/cabe2/lectures/webscience/docs/jena.pdf> I've
gotten my workspace set up. I've removed the package identifier from my code
java -cp ... <fullname>
java -cp ... a.b.C
where C has the static main method
<https://stackoverflow.com/questions/36402759/error-could-
Post by Cumulative Knowledge
not-find-or-load-main-class-classdemo>
.
org/apache/jena/rdf/model/ModelFactory at
Tutorial01.main(Tutorial01.java:34)
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)
I think it's a JENAROOT Issue. I think I'm setting it and adding it
<https://stackoverflow.com/questions/28177971/tdbloader2-fai
ls-with-classpath-error/28181902#28181902>
to the path correctly. It's also mentioned here
<https://jena.apache.org/documentation/tools/>, but I haven't been able to
troubleshoot it yet.
Anybody can point me in the right direction?
Thanks,
Louis
Cumulative Knowledge
2018-04-23 16:47:22 UTC
Permalink
Could it be that I need to rename the JAR files? As far as I can tell
everything is pointing in the correct direction. The JAR files currently
have the version number in their name.

Does the .java file have to be in a specific location or do I need to have
a package identifier included in the file? I previously removed the pack
identifier (package jena.examples.rdf ;) based on a Stackoverflow page.


On Sun, Apr 22, 2018 at 3:03 PM, Cumulative Knowledge <
Post by Cumulative Knowledge
I think I must be getting closer, but I'm still getting the same error.
Now that I'm escaping the *, the path seems correct.
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
$JENA_HOME
/Users/username/Documents/jena/apachejena370
echo $JENAROOT
/Users/username/Documents/jena/apachejena370
$ echo $CLASSPATH
/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/
Home/bin:/Users/username/Documents/jena/apachejena370/lib/*
$ sudo java Tutorial01
org/apache/jena/rdf/model/ModelFactory
at Tutorial01.main(Tutorial01.java:34)
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
$ sudo javac Tutorial01.java
Tutorial01.java:21: error: package org.apache.jena.rdf.model does not exist
import org.apache.jena.rdf.model.*;
^
Tutorial01.java:22: error: package org.apache.jena.vocabulary does not
exist
import org.apache.jena.vocabulary.*;
^
Tutorial01.java:34: error: cannot find symbol
Model model = ModelFactory.createDefaultModel();
^
symbol: class Model
location: class Tutorial01
Tutorial01.java:34: error: cannot find symbol
Model model = ModelFactory.createDefaultModel();
^
symbol: variable ModelFactory
location: class Tutorial01
Tutorial01.java:37: error: cannot find symbol
Resource johnSmith = model.createResource(personURI);
^
symbol: class Resource
location: class Tutorial01
Tutorial01.java:40: error: cannot find symbol
johnSmith.addProperty(VCARD.FN, fullName);
^
symbol: variable VCARD
location: class Tutorial01
6 errors
Post by Cumulative Knowledge
Hi Andy,
Thanks for the help. I'm still getting the same error. Right now I
have JENAROOT and JENA_HOME set to the same path.
$ export CLASSPATH=$CLASSPATH:$JENA_HOME/lib/*
You need to escape the * to stop it be shell expansion. The * needs to be
passed to java.
export CLASSPATH=$CLASSPATH:$JENA_HOME/lib/\*
Post by Cumulative Knowledge
$ echo $CLASSPATH
This does not agree with the line above - no ":" after whatever
$CLASSPATH was before the export.
/Users/username/Documents/jena/apachejena370/lib/collection-0.7.jar
Post by Cumulative Knowledge
/Users/username/Documents/jena/apachejena370/lib/commons-cli-1.4.jar
/Users/username/Documents/jena/apachejena370/lib/commons-codec-1.11.jar
/Users/username/Documents/jena/apachejena370/lib/commons-csv-1.5.jar
/Users/username/Documents/jena/apachejena370/lib/commons-io-2.6.jar
/Users/username/Documents/jena/apachejena370/lib/commons-lang3-3.4.jar
/Users/username/Documents/jena/apachejena370/lib/httpclient-4.5.3.jar
/Users/username/Documents/jena/apachejena370/lib/httpclient-
cache-4.5.3.jar
/Users/username/Documents/jena/apachejena370/lib/httpcore-4.4.6.jar
/Users/username/Documents/jena/apachejena370/lib/jackson-ann
otations-2.9.0.jar
/Users/username/Documents/jena/apachejena370/lib/jackson-core-2.9.0.jar
/Users/username/Documents/jena/apachejena370/lib/jackson-dat
abind-2.9.0.jar
/Users/username/Documents/jena/apachejena370/lib/jcl-over-sl
f4j-1.7.25.jar
/Users/username/Documents/jena/apachejena370/lib/jena-arq-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-base-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-cmds-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-core-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-b
ase-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-i
ndex-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-t
rans-data-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-dboe-t
ransaction-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-iri-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-rdfcon
nection-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-shaded
-guava-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-tdb-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jena-tdb2-3.7.0.jar
/Users/username/Documents/jena/apachejena370/lib/jsonld-java-0.11.1.jar
/Users/username/Documents/jena/apachejena370/lib/libthrift-0.10.0.jar
/Users/username/Documents/jena/apachejena370/lib/log4j-1.2.17.jar
/Users/username/Documents/jena/apachejena370/lib/slf4j-api-1.7.25.jar
/Users/username/Documents/jena/apachejena370/lib/slf4j-log4j
12-1.7.25.jar
/Users/username/Documents/jena/apachejena370/lib/xercesImpl-2.11.0.jar
/Users/username/Documents/jena/apachejena370/lib/xml-apis-1.4.01.jar
Any thoughts?
Thanks,
Louis
Louis,
Post by Andy Seaborne
The exception means that the classpth does not contain the jena-core
jar.
Put all the jars from the distribution lib directory in the classpath.
Nowadays in java you can put '...\lib\*' on the classpath and it will
include all the jars in that directory.
See the bat scripts in the download or
https://github.com/apache/jena/tree/master/apache-jena/bat
then print out the classpath to make sure it is right.
Andy
I'm getting Apache Jena set up and am having some issues. I think my
Post by Cumulative Knowledge
issue
is with environment variable, but I'm not sure.
Based on this tutorial
<http://staff.um.edu.mt/cabe2/lectures/webscience/docs/jena.pdf> I've
gotten my workspace set up. I've removed the package identifier from my
code
java -cp ... <fullname>
java -cp ... a.b.C
where C has the static main method
<https://stackoverflow.com/questions/36402759/error-could-
Post by Cumulative Knowledge
not-find-or-load-main-class-classdemo>
.
org/apache/jena/rdf/model/ModelFactory at
Tutorial01.main(Tutorial01.java:34)
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)
I think it's a JENAROOT Issue. I think I'm setting it and adding it
<https://stackoverflow.com/questions/28177971/tdbloader2-fai
ls-with-classpath-error/28181902#28181902>
to the path correctly. It's also mentioned here
<https://jena.apache.org/documentation/tools/>, but I haven't been
able
to
troubleshoot it yet.
Anybody can point me in the right direction?
Thanks,
Louis
Loading...