Java中httpclient.jar和httpcore.jar版本差异带来的异常
2016-08-01 00:00
519 查看
转载请注明来源:http://blog.csdn.net/loongshawn/article/details/50590660
前言说明:当前我的工程中使用的httpclient-4.3.6.jar和httpcore-4.3.3.jar版本的包。
今天执行阿里云的OSS相关操作时,首先提示以下异常:
详细如下:
从上面报错提示可以看出,是org/apache/http/ssl/TrustStrategy下面找不到TrustStrategy这个类,我查了下依赖中的httpclient-4.3.6.jar和httpcore-4.3.3.jar两个包,均没有这个类。
而4.4版本中有ssl路径:
及对应org/apache/http/ssl/TrustStrategy方法。
很明显是版本不对,应该换成新版本。
重新执行代码,上面异常已经消失,不过出现新异常:
异常详细:
很明显是版本不对,是由于httpclient-4.3.6.jar缺少NoopHostnameVerifier方法:
而4.4版本中有这个方法:
应该换成新版本,即换成httpclient-4.4.jar
查看下jar包中相应路径存在上面那个类。
最后再次执行,执行成功,无异常!
所以,下次碰到以下两个异常时:
1、
2、
需要升级httpclient.jar和httpcore.jar两个包的版本,4.3的版本中不含有上述两个类,需要同时升级到4.4版本。
即替换为httpclient-4.4.jar和httpcore-4.4.jar
前言说明:当前我的工程中使用的httpclient-4.3.6.jar和httpcore-4.3.3.jar版本的包。
<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.3.3</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.3.6</version> </dependency>
今天执行阿里云的OSS相关操作时,首先提示以下异常:
java.lang.ClassNotFoundException: org.apache.http.ssl.TrustStrategy
详细如下:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ssl/TrustStrategy at com.aliyun.oss.OSSClient.<init>(OSSClient.java:246) at com.aliyun.oss.OSSClient.<init>(OSSClient.java:206) at com.autonavi.oss.client.DefaultOSSClient.<clinit>(DefaultOSSClient.java:12) at com.autonavi.oss.put.Upload.put(Upload.java:20) at com.autonavi.oss.put.Upload.main(Upload.java:58) Caused by: java.lang.ClassNotFoundException: org.apache.http.ssl.TrustStrategy at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 5 more
从上面报错提示可以看出,是org/apache/http/ssl/TrustStrategy下面找不到TrustStrategy这个类,我查了下依赖中的httpclient-4.3.6.jar和httpcore-4.3.3.jar两个包,均没有这个类。
而4.4版本中有ssl路径:
及对应org/apache/http/ssl/TrustStrategy方法。
很明显是版本不对,应该换成新版本。
<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.4</version> </dependency>
重新执行代码,上面异常已经消失,不过出现新异常:
java.lang.NoClassDefFoundError: org/apache/http/conn/ssl/NoopHostnameVerifier
异常详细:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/conn/ssl/NoopHostnameVerifier at com.aliyun.oss.common.comm.DefaultServiceClient.createHttpClientConnectionManager(DefaultServiceClient.java:230) at com.aliyun.oss.common.comm.DefaultServiceClient.<init>(DefaultServiceClient.java:78) at com.aliyun.oss.OSSClient.<init>(OSSClient.java:246) at com.aliyun.oss.OSSClient.<init>(OSSClient.java:206) at com.autonavi.oss.client.DefaultOSSClient.<clinit>(DefaultOSSClient.java:12) at com.autonavi.oss.put.Upload.put(Upload.java:20) at com.autonavi.oss.put.Upload.main(Upload.java:58) Caused by: java.lang.ClassNotFoundException: org.apache.http.conn.ssl.NoopHostnameVerifier at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 7 more
很明显是版本不对,是由于httpclient-4.3.6.jar缺少NoopHostnameVerifier方法:
而4.4版本中有这个方法:
应该换成新版本,即换成httpclient-4.4.jar
<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.4</version> </dependency>
查看下jar包中相应路径存在上面那个类。
最后再次执行,执行成功,无异常!
所以,下次碰到以下两个异常时:
1、
java.lang.ClassNotFoundException: org.apache.http.ssl.TrustStrategy
2、
java.lang.NoClassDefFoundError: org/apache/http/conn/ssl/NoopHostnameVerifier
需要升级httpclient.jar和httpcore.jar两个包的版本,4.3的版本中不含有上述两个类,需要同时升级到4.4版本。
即替换为httpclient-4.4.jar和httpcore-4.4.jar
相关文章推荐
- TrustStrategy——Java中httpclient.jar和httpcore.jar版本差异带来的异常
- Java中httpclient.jar和httpcore.jar版本差异带来的异常
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar
- jstl学习常见错误一: The absolute uri: http://java.sun.com/jst/core cannot be resolved in either web.xml or the jar files deployed with
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar
- This absolute uri http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar
- 修改httpcore.jar的源码,查看Httpclient的http协议请求头部和响应头部
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar [转]
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar
- http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed wit
- The absolute uri: http://java.sun.com/jstl/core cannot be resolved in either web.xml or the jar file
- http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed wit
- Jsp http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar
- java,eclipse中如何添加httpclient.jar
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files
- 使用Jstl异常:HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in
- This absolute uri http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar