1

我收到错误

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

在运行一个简单的 Jena 示例时,但我的 Mavenpom.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
4

1 回答 1

0

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

[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,那么可能有一些本地干扰。

于 2018-04-09T15:34:10.357 回答