1

I am getting the error

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/util/XMLChar
    at org.apache.jena.shared.impl.PrefixMappingImpl.checkLegal(PrefixMappingImpl.java:172)

when running a simple Jena example, but I do have these two dependencies in my Maven pom.xml file:

<dependency>
    <groupId>org.apache.jena</groupId>
    <artifactId>apache-jena-libs</artifactId>
    <type>pom</type>
    <version>3.6.0</version>
</dependency>
<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.11.0</version>
</dependency>

I checked the downloadable Jena archive and its lib directory does contain the Xerces 2.11.0 jar file, so the version is correct.

What is missing here?

Updates:

AndyS points out the dependency is not needed and that NoClassDefFoundError is different from the more common ClassNotFoundException.

The error happens without the dependency. As for NoClassDefFoundError, not sure what may be causing it. My code is extremely simple:

String filename = "test.jsonld";

Model model = ModelFactory.createDefaultModel() ;
model.read(filename) ;

with test.jsonld being

{
    "@id": "http://store.example.com/",
    "@type": "Store",
    "name": "Links Bike Shop",
    "description": "The most \"linked\" bike store on earth!"
}

The full output including exceptions is below. I am not sure how to start troubleshooting this, any suggestions?

12:46:26,102 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
12:46:26,102 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
12:46:26,102 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/Users/E26638/git/aic-praise/target/classes/logback.xml]
12:46:26,103 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs multiple times on the classpath.
12:46:26,104 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/C:/Users/E26638/git/aic-expresso/target/classes/logback.xml]
12:46:26,104 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/C:/Users/E26638/git/aic-praise/target/classes/logback.xml]
12:46:26,159 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
12:46:26,176 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word logxtracemsg with class [com.sri.ai.util.log.LogXTraceConverter]
12:46:26,176 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
12:46:26,189 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [stdout]
12:46:26,251 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.sri.ai.grinder.helper.Trace] to false
12:46:26,252 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.sri.ai.grinder.helper.Trace level set to TRACE
12:46:26,252 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.sri.ai.grinder.helper.Justification] to false
12:46:26,252 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.sri.ai.grinder.helper.Justification level set to TRACE
12:46:26,252 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - ROOT level set to DEBUG
12:46:26,252 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [stdout] to Logger[ROOT]
12:46:26,253 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
12:46:26,253 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@67b6d4ae - Registering current configuration as safe fallback point

12:46:26.258 [main] DEBUG Jena - Jena initialization
12:46:26.335 [main] DEBUG org.apache.jena.util.FileManager - Add location: LocatorFile
12:46:26.335 [main] DEBUG org.apache.jena.util.FileManager - Add location: ClassLoaderLocator
12:46:26.337 [main] DEBUG org.apache.jena.util.LocationMapper - Failed to find configuration: file:location-mapping.rdf;file:location-mapping.n3;file:location-mapping.ttl;file:etc/location-mapping.rdf;file:etc/location-mapping.n3;file:etc/location-mapping.ttl
12:46:26.337 [main] DEBUG org.apache.jena.util.FileManager - Add location: LocatorFile
12:46:26.338 [main] DEBUG org.apache.jena.util.FileManager - Add location: LocatorURL
12:46:26.338 [main] DEBUG org.apache.jena.util.FileManager - Add location: ClassLoaderLocator
12:46:26.343 [main] DEBUG o.a.j.r.s.stream.JenaIOEnvironment - Failed to find configuration: location-mapping.ttl;location-mapping.rdf;location-mapping.n3;etc/location-mapping.rdf;etc/location-mapping.n3;etc/location-mapping.ttl
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/util/XMLChar
    at org.apache.jena.shared.impl.PrefixMappingImpl.checkLegal(PrefixMappingImpl.java:172)
    at org.apache.jena.shared.impl.PrefixMappingImpl.setNsPrefix(PrefixMappingImpl.java:72)
    at org.apache.jena.shared.PrefixMapping.<clinit>(PrefixMapping.java:219)
    at org.apache.jena.sparql.ARQConstants.<clinit>(ARQConstants.java:106)
    at org.apache.jena.query.ARQ.init(ARQ.java:588)
    at org.apache.jena.sparql.system.InitARQ.start(InitARQ.java:29)
    at org.apache.jena.system.JenaSystem.lambda$init$2(JenaSystem.java:119)
    at java.util.ArrayList.forEach(Unknown Source)
    at org.apache.jena.system.JenaSystem.forEach(JenaSystem.java:194)
    at org.apache.jena.system.JenaSystem.forEach(JenaSystem.java:171)
    at org.apache.jena.system.JenaSystem.init(JenaSystem.java:117)
    at org.apache.jena.rdf.model.ModelFactory.<clinit>(ModelFactory.java:49)
    at com.sri.ai.praise.jdsonld.ReadJenaJSONLD.main(ReadJenaJSONLD.java:11)
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.util.XMLChar
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 13 more
user118967
  • 4,895
  • 5
  • 33
  • 54
  • 1
    You do not need to include a dependency on Xerces because it is recursively included by "apache-jena-libs". – AndyS Apr 08 '18 at 15:25
  • 1
    ClassNotFoundException (class path problem) is not the same as NoClassDefFoundError. NoClassDefFoundError can be due to several things but indicates the class was found but could not be loaded. Without more details, it isn't possible to say much more. – AndyS Apr 08 '18 at 15:26
  • Thanks, that's very useful info. Please see updates to question for more details. Not sure how to start troubleshooting this. – user118967 Apr 08 '18 at 20:01

1 Answers1

0

maven dependencies for a project that solely depends on org.apache.jena:apache-jena-libs:pom:3.6.0 should look like this:

[INFO] org.apache.jena:jena-reports-version:jar:0.0.0-SNAPSHOT [INFO] \- org.apache.jena:apache-jena-libs:pom:3.6.0:compile [INFO] +- org.apache.jena:jena-tdb:jar:3.6.0:compile [INFO] | \- org.apache.jena:jena-arq:jar:3.6.0:compile [INFO] | +- org.apache.jena:jena-core:jar:3.6.0:compile [INFO] | | +- org.apache.jena:jena-iri:jar:3.6.0:compile [INFO] | | +- xerces:xercesImpl:jar:2.11.0:compile [INFO] | | | \- xml-apis:xml-apis:jar:1.4.01:compile ...

If it is not finding xerces, then there might be something local interfering.

AndyS
  • 16,345
  • 17
  • 21