在扩展以前工作的项目时,我似乎已经消除了对maven的依赖。
junit片段:
Client interimClient = ClientBuilder.newClient();
WebTarget interim = interimClient.target(REST_TARGET_URL);
result persistedResult = interim.request()
.post(Entity.entity(testResult, MediaType.APPLICATION_JSON), Result.class);
Assert.assertEquals("A result should be persisted ", "TEST", persistedResult.getId());
错误:
java.lang.NoClassDefFoundError: org/apache/http/conn/ssl/X509HostnameVerifier
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:116)
at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:164)
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
我尝试添加依赖项
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0-alpha4</version>
</dependency>
......但后来
java.lang.NoClassDefFoundError: org/apache/http/conn/scheme/SchemeSocketFactory
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
鉴于这在几个小时之前就已经开始工作,每次连续的依赖性错误之后似乎都会滑下兔子洞。希望这是一个众所周知的跳跃点,有人可以帮助指导我。 TIY。
答案 0 :(得分:3)
运行JUnit测试时,我们收到类似的错误消息。我们的依赖版本来自org.wildfly:wildfly-parent:10.0.0.Final。
最初的错误是:
java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
添加以下依赖项解决了初始错误
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<scope>provided</scope>
</dependency>
然后我们收到了第二个错误:
java.lang.NoClassDefFoundError: org/apache/http/conn/ssl/X509HostnameVerifier
添加以下依赖项解决了第二个(X509HostnameVerifier)错误
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>provided</scope>
</dependency>
添加这两个依赖项后问题就解决了。 resteasy-client解析为版本3.0.14.Final,httpclient解析为org.wildfly的版本4.5:wildfly-parent:10.0.0.Final。
答案 1 :(得分:1)
看来我的jax-rs相关依赖项的某些变化导致了这个错误。在将它们简化为以下内容后,我能够恢复良好的状态:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>javax.ejb-api</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<scope>test</scope>
</dependency>