gpt4 book ai didi

java - Jena 在要求缺席 Xerces 的类(class)时失败,而 Xerces 2 已包含在内

转载 作者:太空宇宙 更新时间:2023-11-04 10:33:44 28 4
gpt4 key购买 nike

我收到错误

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

最佳答案

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


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

如果没有找到 xerces,则可能存在本地干扰。

关于java - Jena 在要求缺席 Xerces 的类(class)时失败,而 Xerces 2 已包含在内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49716367/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com