问题描述
我有一个Java Maven项目,该项目是我前一段时间开发的,现在不再起作用.它使用了一个父pom以及另一个我认为已更改Jena版本的Maven项目,并且还使用了一个使用Jena的外部库. Maven依赖项是:
I have a Java Maven project that I developed a while ago and that doesn't work anymore. It uses a parent pom together with another Maven project in which I think the Jena version was changed and it also uses an external library that uses Jena. The Maven dependency is:
<dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>jena</artifactId>
<version>2.6.4</version>
</dependency>
执行测试时,出现以下错误:
When I execute my tests I get the following errors:
- java.lang.NoClassDefFoundError:无法初始化类com.hp.hpl.jena.query.ARQ
- java.lang.NoClassDefFoundError:org/apache/jena/iri/IRIFactory 在org.openjena.riot.system.PrefixMap.add(PrefixMap.java:54)在com.hp.hpl.jena.sparql.util.MappingRegistry.addPrefixMapping(MappingRegistry.java:33)在com.hp.hpl.jena.query.ARQ.init(ARQ.java:449)[...]
- java.lang.NoClassDefFoundError: Could not initialize classcom.hp.hpl.jena.query.ARQ
- java.lang.NoClassDefFoundError: org/apache/jena/iri/IRIFactoryat org.openjena.riot.system.PrefixMap.add(PrefixMap.java:54)at com.hp.hpl.jena.sparql.util.MappingRegistry.addPrefixMapping(MappingRegistry.java:33)at com.hp.hpl.jena.query.ARQ.init(ARQ.java:449) [...]
错误不是由我的代码直接引发的,而是由我所包含的库引发的.我可以通过在父pom中降级Jena版本来防止这种情况吗?
The errors are not thrown by my code directly but by the library I include. Can I prevent this by downgrading the Jena version in the parent pom or what can I do here?
P.S .:我现在有一个最小的代码示例来重现该错误(java.lang.NoClassDefFoundError:org/apache/jena/iri/IRIFactory):
P.S.: I now have a minimal code example that reproduces the error (java.lang.NoClassDefFoundError: org/apache/jena/iri/IRIFactory):
import org.junit.Test;
import com.hp.hpl.jena.query.ARQ;
public class DependencyTest
{
@Test
public void testARQ()
{
ARQ a = new ARQ();
}
}
我想它来自于这种依赖性:
And I guess it comes from this dependency:
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>2.9.1-incubating-SNAPSHOT</version>
</dependency>
我知道可能是工厂而不是构造函数,但是我想这仍然可以说明问题出在哪里.
I know there is probably a factory instead of a constructor but I guess this still shows where the problem is.
P.S .:我注意到我有依赖项"jena","arq"和"jena-arq":
P.S.: I noticed that I had the dependencies "jena", "arq" and "jena-arq":
<dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>arq</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>2.9.1-incubating-SNAPSHOT</version>
</dependency>
dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>jena</artifactId>
<version>2.6.4</version>
</dependency>
所以我想也许我有太多重叠的依赖项,并注释掉了"jena"和"arq".但是我仍然得到错误
So I thought maybe I have too much overlapping dependencies and commented out "jena" and "arq". But I still get the error
java.lang.NoClassDefFoundError: Could not initialize class com.hp.hpl.jena.query.ARQ
at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.<init> [...]
我还尝试过强制使用非快照版本2.9.0进行孵化,但是无论是否使用"jena"和"arq"依赖性,我仍然会收到NoClassDefFoundError.
I also tried out forcing a non-snapshot-version 2.9.0-incubating, but then I still get the NoClassDefFoundError with and without using the "jena" and "arq"-dependencies.
P.P.S.:
即使使用以下依赖项,我仍然会遇到相同的错误:
I still get the same error even when I use the following dependencies:
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>2.9.0-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>2.7.0-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-iri</artifactId>
<version>2.7.0-incubating</version>
</dependency>
推荐答案
我终于解决了这个错误,排除了一些库中作为传递依赖而引入的"jena" -Dependency.
I finally resolved this error by excluding the "jena"-Dependency brought in as a transitive dependency from some library.
这篇关于Maven的Jena NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!