Radu Lozovanu
Radu Lozovanu

Reputation: 167

java.lang.NoClassDefFoundError: org/apache/http/impl/conn/ManagedHttpClientConnectionFactory

I have 2 different porltets that use the same component HttpClientBuilder.java, first it's working ok, but the second give me this 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)

a part of code that generate this error:

long beginTime= (new Date()).getTime();
            CloseableHttpClient client = HttpClientBuilder.create().build();
            HttpGet request = new HttpGet(this.url);

            // add request header
            CloseableHttpResponse response = client.execute(request);

Can some one help me please ?

EDIT: We are using WebLogic Portal from Oracle

Upvotes: 2

Views: 2716

Answers (2)

devwebcl
devwebcl

Reputation: 3203

Certainly it is a classloading issue, and that class canbe found at: httpclient-4.5.jar

You can check from which jar file is the functional portlet retrieving that class: http://devwebcl.blogspot.cl/2016/03/logging-of-class-loading-and-unloading.html

One approach is to put the following code in the mentioned code:

  ClassLoader cl = ClassLoader.getSystemClassLoader();

  URL[] urls = ((URLClassLoader)cl).getURLs();

  for(URL url: urls){
     System.out.println(url.getFile());
  }

or use: -verbose:class system property, but this is more verbose and you need to change your startup scripts.

This way you can identify which jar file is missing. (maybe it is a different name for httpclient)

Upvotes: 0

贾宇鹏
贾宇鹏

Reputation: 11

If you are using Maven to manage your dependency you can add a new dependency as below in your pom.xml

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.3.5</version>
    </dependency>

Provide more info of your environment, if this does not help .

Upvotes: 1

Related Questions