Discussion:
java.lang.NoClassDefFoundError: org/apache/http/config/Lookup
Russell Bateman
2018-01-19 20:37:43 UTC
Permalink
I haven't used an Apache HTTP client in a few years. So, I've started
fresh. Having written precious little code carefully following
http://hc.apache.org/httpcomponents-client-4.5.x/quickstart.html, I get
this exception as soon as I call createDefault():

/*    CloseableHttpClient client = HttpClients.createDefault();*/
    HttpGet             get    = new HttpGet( query );

    get.setHeader( ACCEPT_CHARSET, UTF8 );
    get.setHeader( "Accept", "application/xml,application/json" );

    CloseableHttpResponse response = client.execute( get );
    HttpEntity            entity   = response.getEntity();

    try
    {
      return entity.getContent();
    }
    catch( IOException e )
    {
      throw new IOException( e.getMessage() + " occurred getting query
response" );
    }
    finally
    {
      response.close();
    }

I die similarly in my POST requests.

The full stack trace follows (below), but here's what I have in
/pom.xml/:. I added the httpcore out of desperation and googling for
this problem. No matter, it happens with or without it and no matter
what version I add.

    <apache.http.client.version>*4.5.4*</apache.http.client.version>

*    <dependency>**
**<groupId>org.apache.httpcomponents</groupId>**
**<artifactId>httpclient</artifactId>**
**<version>${apache.http.client.version}</version>**
**    </dependency>*
    <dependency>
<groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpcore</artifactId>
      <version>*4.4.7*</version>
    </dependency>

What have I done wrong?

Here's the stacktrace:

*java.lang.NoClassDefFoundError: org/apache/http/config/Lookup*

    at
org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:56)
    at
com.imatsolutions.utilities.ApacheClientOperations.getQuery(ApacheClientOperations.java:123)
    at
com.imatsolutions.utilities.ApacheClientOperationsTest.testStatus(ApacheClientOperationsTest.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.apache.http.config.Lookup
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 29 more
Oleg Kalnichevski
2018-01-19 21:28:01 UTC
Permalink
Post by Russell Bateman
I haven't used an Apache HTTP client in a few years. So, I've
started 
fresh. Having written precious little code carefully following 
http://hc.apache.org/httpcomponents-client-4.5.x/quickstart.html, I
get 
/*    CloseableHttpClient client = HttpClients.createDefault();*/
     HttpGet             get    = new HttpGet( query );
     get.setHeader( ACCEPT_CHARSET, UTF8 );
     get.setHeader( "Accept", "application/xml,application/json" );
     CloseableHttpResponse response = client.execute( get );
     HttpEntity            entity   = response.getEntity();
     try
     {
       return entity.getContent();
     }
     catch( IOException e )
     {
       throw new IOException( e.getMessage() + " occurred getting
query 
response" );
     }
     finally
     {
       response.close();
     }
I die similarly in my POST requests.
The full stack trace follows (below), but here's what I have in 
/pom.xml/:. I added the httpcore out of desperation and googling for 
this problem. No matter, it happens with or without it and no matter 
what version I add.
     <apache.http.client.version>*4.5.4*</apache.http.client.version>
*    <dependency>**
**<groupId>org.apache.httpcomponents</groupId>**
**<artifactId>httpclient</artifactId>**
**<version>${apache.http.client.version}</version>**
**    </dependency>*
     <dependency>
<groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpcore</artifactId>
       <version>*4.4.7*</version>
     </dependency>
What have I done wrong?
Your dependency tree appears to be wrong. Something is pulling an old
version of HttpCore.

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Russell Bateman
2018-01-19 21:46:58 UTC
Permalink
Oleg,

Thank you for responding.

What version of httpcore should I put there? There is apparently non
corresponding to 4.5.4. I tried httpcore-4.4.8 and the result was the
same. 4.4.8 is the latest version I can find in Maven.

https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore

Russ
Post by Oleg Kalnichevski
Post by Russell Bateman
I haven't used an Apache HTTP client in a few years. So, I've
started
fresh. Having written precious little code carefully following
http://hc.apache.org/httpcomponents-client-4.5.x/quickstart.html, I get
/*    CloseableHttpClient client = HttpClients.createDefault();*/
     HttpGet             get    = new HttpGet( query );
     get.setHeader( ACCEPT_CHARSET, UTF8 );
     get.setHeader( "Accept", "application/xml,application/json" );
     CloseableHttpResponse response = client.execute( get );
     HttpEntity            entity   = response.getEntity();
     try
     {
       return entity.getContent();
     }
     catch( IOException e )
     {
       throw new IOException( e.getMessage() + " occurred getting
query
response" );
     }
     finally
     {
       response.close();
     }
I die similarly in my POST requests.
The full stack trace follows (below), but here's what I have in
/pom.xml/:. I added the httpcore out of desperation and googling for
this problem. No matter, it happens with or without it and no matter
what version I add.
     <apache.http.client.version>*4.5.4*</apache.http.client.version>
*    <dependency>**
**<groupId>org.apache.httpcomponents</groupId>**
**<artifactId>httpclient</artifactId>**
**<version>${apache.http.client.version}</version>**
**    </dependency>*
     <dependency>
<groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpcore</artifactId>
       <version>*4.4.7*</version>
     </dependency>
What have I done wrong?
Your dependency tree appears to be wrong. Something is pulling an old
version of HttpCore.
Oleg
---------------------------------------------------------------------
Oleg Kalnichevski
2018-01-19 22:12:08 UTC
Permalink
Post by Russell Bateman
Oleg,
Thank you for responding.
What version of httpcore should I put there? There is apparently non 
corresponding to 4.5.4. I tried httpcore-4.4.8 and the result was
the 
same. 4.4.8 is the latest version I can find in Maven.
https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore
Russ
The version is correct but _something else_ (like AWS SDK) is pulling
older code from your classpath. You need to find out what it is.

See this SO thread. It might help

https://stackoverflow.com/questions/21864521/java-lang-nosuchfielderror
-org-apache-http-message-basiclineformatter-instance

Oleg
Post by Russell Bateman
Post by Oleg Kalnichevski
Post by Russell Bateman
I haven't used an Apache HTTP client in a few years. So, I've started
fresh. Having written precious little code carefully following
http://hc.apache.org/httpcomponents-client-4.5.x/quickstart.html, I
get
/*    CloseableHttpClient client = HttpClients.createDefault();*/
      HttpGet             get    = new HttpGet( query );
      get.setHeader( ACCEPT_CHARSET, UTF8 );
      get.setHeader( "Accept", "application/xml,application/json"
);
      CloseableHttpResponse response = client.execute( get );
      HttpEntity            entity   = response.getEntity();
      try
      {
        return entity.getContent();
      }
      catch( IOException e )
      {
        throw new IOException( e.getMessage() + " occurred
getting
query
response" );
      }
      finally
      {
        response.close();
      }
I die similarly in my POST requests.
The full stack trace follows (below), but here's what I have in
/pom.xml/:. I added the httpcore out of desperation and googling for
this problem. No matter, it happens with or without it and no matter
what version I add.
     
<apache.http.client.version>*4.5.4*</apache.http.client.version>
*    <dependency>**
**<groupId>org.apache.httpcomponents</groupId>**
**<artifactId>httpclient</artifactId>**
**<version>${apache.http.client.version}</version>**
**    </dependency>*
      <dependency>
<groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>*4.4.7*</version>
      </dependency>
What have I done wrong?
Your dependency tree appears to be wrong. Something is pulling an old
version of HttpCore.
Oleg
-----------------------------------------------------------------
----
g
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Russell Bateman
2018-01-19 22:15:12 UTC
Permalink
Ah, okay, I get that. I'll go look for it.

Thanks!
Post by Oleg Kalnichevski
Post by Russell Bateman
Oleg,
Thank you for responding.
What version of httpcore should I put there? There is apparently non
corresponding to 4.5.4. I tried httpcore-4.4.8 and the result was the
same. 4.4.8 is the latest version I can find in Maven.
https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore
Russ
The version is correct but _something else_ (like AWS SDK) is pulling
older code from your classpath. You need to find out what it is.
See this SO thread. It might help
https://stackoverflow.com/questions/21864521/java-lang-nosuchfielderror
-org-apache-http-message-basiclineformatter-instance
Oleg
Post by Russell Bateman
Post by Oleg Kalnichevski
Post by Russell Bateman
I haven't used an Apache HTTP client in a few years. So, I've started
fresh. Having written precious little code carefully following
http://hc.apache.org/httpcomponents-client-4.5.x/quickstart.html, I
get
/*    CloseableHttpClient client = HttpClients.createDefault();*/
      HttpGet             get    = new HttpGet( query );
      get.setHeader( ACCEPT_CHARSET, UTF8 );
      get.setHeader( "Accept", "application/xml,application/json"
);
      CloseableHttpResponse response = client.execute( get );
      HttpEntity            entity   = response.getEntity();
      try
      {
        return entity.getContent();
      }
      catch( IOException e )
      {
        throw new IOException( e.getMessage() + " occurred
getting
query
response" );
      }
      finally
      {
        response.close();
      }
I die similarly in my POST requests.
The full stack trace follows (below), but here's what I have in
/pom.xml/:. I added the httpcore out of desperation and googling for
this problem. No matter, it happens with or without it and no matter
what version I add.
<apache.http.client.version>*4.5.4*</apache.http.client.version>
*    <dependency>**
**<groupId>org.apache.httpcomponents</groupId>**
**<artifactId>httpclient</artifactId>**
**<version>${apache.http.client.version}</version>**
**    </dependency>*
      <dependency>
<groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>*4.4.7*</version>
      </dependency>
What have I done wrong?
Your dependency tree appears to be wrong. Something is pulling an old
version of HttpCore.
Oleg
-----------------------------------------------------------------
----
g
---------------------------------------------------------------------
Loading...