我有2个不同的porltets使用相同的组件HttpClientBuilder.java,首先它工作正常,但第二个给我这个erorr:
java.lang.NoClassDefFoundError: org/apache/http/impl/conn/ManagedHttpClientConnectionFactory
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.(PoolingHttpClientConnectionManager.java:493)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.(PoolingHttpClientConnectionManager.java:149)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.(PoolingHttpClientConnectionManager.java:138)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.(PoolingHttpClientConnectionManager.java:114)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726)
at com.firm.msite.portlet.shops.StoreJSON.load(StoreJSON.java:55)
at com.firm.msite.portlet.shops.ShopsPortlet.doView(ShopsPortlet.java:137)
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.bea.portlet.container.PortletStub.doRender(PortletStub.java:942)
at com.bea.portlet.container.FilterChainGenerator.runFilterChain(FilterChainGenerator.java:125)
at com.bea.portlet.container.PortletStub.render(PortletStub.java:414)
at com.bea.portlet.container.AppContainer.renderStub(AppContainer.java:1123)
at com.bea.portlet.container.AppContainer.invokeRender(AppContainer.java:1055)
at com.bea.netuix.servlets.controls.content.JavaPortletContent.fireRender(JavaPortletContent.java:267)
at com.bea.netuix.servlets.controls.content.JavaPortletContent.renderInternal(JavaPortletContent.java:162)
at com.bea.netuix.servlets.controls.content.JavaPortletContent.beginRender(JavaPortletContent.java:108)
at com.bea.netuix.nf.ControlLifecycle$7.visit(ControlLifecycle.java:485)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:518)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
生成此错误的代码的一部分:
long beginTime= (new Date()).getTime();
CloseableHttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(this.url);
// add request header
CloseableHttpResponse response = client.execute(request);
有人可以帮我吗?
编辑:我们正在使用Oracle的WebLogic Portal
答案 0 :(得分:1)
如果您使用Maven来管理您的依赖项,您可以在pom.xml中添加如下所示的新依赖项
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
如果这样做无效,请提供有关您环境的更多信息。
答案 1 :(得分:0)
当然这是一个类加载问题,该类可以在以下位置找到:httpclient-4.5.jar
您可以检查哪个jar文件是检索该类的功能portlet:http://devwebcl.blogspot.cl/2016/03/logging-of-class-loading-and-unloading.html
一种方法是将以下代码放在上述代码中:
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader)cl).getURLs();
for(URL url: urls){
System.out.println(url.getFile());
}
或使用: -verbose:class 系统属性,但这更详细,您需要更改启动脚本。
这样您就可以识别缺少哪个jar文件。 (也许它是httpclient的另一个名称)