java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE from Mashape Unirest in Java application

前端 未结 5 624
半阙折子戏
半阙折子戏 2020-11-29 22:45

I have a Maven Java project that uses Mashape Unirest for sending HTTP requests to other URLs. I am currently writing an integration test (using TestNG) tha

5条回答
  •  时光说笑
    2020-11-29 23:09

    The only plausible explanation to this problem is there is an older version of HttpCore on the classpath (unless you also want to consider a possibility of green men from Mars messing with your computer remotely from a flying saucer).

    You can add this snippet to your code to find out what jar the class gets picked up from. This might help find out why that jar is on your classpath in the first place.

    ClassLoader classLoader = MyClass.class.getClassLoader();
    URL resource = classLoader.getResource("org/apache/http/message/BasicLineFormatter.class");
    System.out.println(resource);
    

    This basically tells me that in my case the jar resides in the local maven repository and likely to have been added to the classpath by Maven

    jar:file:/home/oleg/.m2/repository/org/apache/httpcomponents/httpcore/4.3.1/httpcore-4.3.1.jar!/org/apache/http/message/BasicLineFormatter.class
    

提交回复
热议问题