当包括Xerces 2时,Jena在要求丢失Xerces的课程时失败了

时间:2018-04-08 09:21:53

标签: java jena xerces xerces2-j

我收到错误

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

运行一个简单的Jena示例,但我在Maven pom.xml文件中确实有这两个依赖项:

<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>

我检查了可下载的Jena存档,其lib目录确实包含Xerces 2.11.0 jar文件,因此版本正确。

这里缺少什么?

更新

AndyS指出不需要依赖,NoClassDefFoundError与更常见的ClassNotFoundException不同。

错误发生时没有依赖项。至于NoClassDefFoundError,不确定可能导致它的原因。我的代码非常简单:

String filename = "test.jsonld";

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

test.jsonld

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

包括例外的完整输出如下。我不知道如何开始排除故障,有什么建议吗?

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

1 个答案:

答案 0 :(得分:0)

仅依赖于org.apache.jena:apache-jena-libs:pom:3.6.0的项目的maven依赖项应如下所示:

[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 ...

如果没有找到xerces,那么可能存在局部干扰。