java.lang.ClassNotFoundException: com.sun.image.codec.jpeg.JPEGCodec
今天迁移老项目到linux服务器,jdk8 ,tomcat8.5遇到这个问题。
java.lang.ClassNotFoundException: com.sun.image.codec.jpeg.JPEGCodec
查询资料得知,原来openjdk从jdk7开始去掉了这个类。
ICEpdfPDF-332
JPEGCodec has been removed from JDK 1.7
引用:http://jira.icesoft.org/browse/PDF-332
处理:
更换为oracle jdk8,解决问题。
这两天都快被这个错误整疯了!!!
最近在写java项目的时候需要用到
- import com.sun.image.codec.jpeg.JPEGCodec;
- import com.sun.image.codec.jpeg.JPEGImageEncoder;
这两个类来把图片写入磁盘。注意:这两个类可是处在系统自带的jre里的rt.jar包里
- FileOutputStream out = new FileOutputStream(targetFile);
- JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
- encoder.encode(mBufferedImage);
本来在本地Eclipse测试的好好的,但是部署到Linux服务器的时候就出错了
- java.lang.ClassNotFoundException: com.sun.image.codec.jpeg.JPEGCodec
- at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
- at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
- at com.vxpai.wechat.util.ImgUtil.imageScale(ImgUtil.java:72)
- at com.vxpai.wechat.webcontroller.UploadController.ss(UploadController.java:68)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:606)
- at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
- at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
- at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
- at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
- at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
- at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
- at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
- at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
- at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
- at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
- at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
- at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
- at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
- at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
- at java.lang.Thread.run(Thread.java:745)
刚开始的时候以为是没有引入rt.jar,将其用maven(我的项目是基于maven建立的)引入,部署上去之后居然还是报错:
- java.lang.UnsatisfiedLinkError: no jpeg in java.library.path
- at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
- at java.lang.Runtime.loadLibrary0(Runtime.java:849)
- at java.lang.System.loadLibrary(System.java:1088)
- at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:67)
- at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:47)
- at java.security.AccessController.doPrivileged(Native Method)
- at sun.awt.image.codec.JPEGImageEncoderImpl.<clinit>(JPEGImageEncoderImpl.java:73)
- at com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(JPEGCodec.java:68)
- at com.vxpai.wechat.util.ImgUtil.imageScale(ImgUtil.java:72)
- at com.vxpai.wechat.webcontroller.UploadController.ss(UploadController.java:68)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:606)
- at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
- at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
- at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
- at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
- at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
- at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
- at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
- at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
- at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
- at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
- at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
- at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
- at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
- at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
最后,果断弃百度google了一下,终于找到了产生java.lang.ClassNotFoundException的原因:The basic explanation is that com.sun.image.codec.jpeg.JPEGCodec and related libraries have long been marked as depreciated, and you should use the ImageIO library instead. 参考地址:http://www.derrickwilliams.com/
原来,在jdk最新的版本中,这jpeg包下的类已经不推荐,所以,果断用ImageIO替换这两个类
- FileOutputStream out = new FileOutputStream(targetFile);
- ImageIO.write(mBufferedImage, type, out);
修改完成,部署,终于OK啦!
java.lang.ClassNotFoundException: com.sun.image.codec.jpeg.JPEGCodec的更多相关文章
- java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/JPEGCodec
java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/JPEGCodec 这个类在 rt.jar 里面 本地开发,jre里有这个包,所以不会 ...
- java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/JPEGCodec 解决方案
使用java生成图片的时候,报了java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/JPEGCodec 错误. 根据这个类的api说明,在 ...
- OpenJDK中java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/ImageFormatException解决办法
http://www.cnblogs.com/xusweeter/p/9667801.html
- Caused by: java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC
Caused by: java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC 缺少com/sun/tools/inte ...
- java.lang.ClassNotFoundException: com.sun.jna.Native
在使用sprng boot加elasticsearch的时候遇到 java.lang.ClassNotFoundException: com.sun.jna.Native,百度之后要我导入 <d ...
- java.lang.ClassNotFoundException: com.sun.xml.ws.spi.ProviderImpl解决办法
问题现象: 这种很可能出现在独立一个简单示例项目中可以用,但是在把webService模块加入系统后,报出这类错误. Exception in thread "main" java ...
- jfinal运行时报错分析java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
这里解释一下,我用maven jetty运行没啥问题的项目,当我切换tomcat时候出现如下错误. 问题1. - jar not loaded. See Servlet Spec 3.0, secti ...
- import com.sun.image.codec.jpeg.JPEGCodec不通过 找不到包
import com.sun.image.codec.jpeg.JPEGCodec; 在Eclipse中处理图片,需要引入两个包: import com.sun.image.codec.jpeg. ...
- import com.sun.image.codec.jpeg.JPEGCodec不通过 找不到包(转载)
http://www.xuebuyuan.com/2008608.html 在Eclipse中处理图片,需要引入两个包:import com.sun.image.codec.jpeg.JPEGCode ...
随机推荐
- python之函数用法id(),了解即可
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法id(),了解即可 #http://www.cnblogs.com/hongfei/p ...
- 在centos (linux) 搭建 eclipse c++开发分环境
网上说得很多,很烦,操作了很多,总有错误,但解决方案很简单.步骤就下面几步就OK了 安装gcc .g++ yum install gcc yum install gcc-c++ 安装jdk,配置jdk ...
- Golang配置文件解析-oozgconf
代码地址如下:http://www.demodashi.com/demo/14411.html 简介 oozgconf基于Golang开发,用于项目中配置文件的读取以及加载,是一个轻量级的配置文件工具 ...
- iOS-高仿支付宝手势解锁(九宫格)
概述 高仿支付宝手势解锁, 通过手势枚举去实现手势密码相对应操作. 详细 代码下载:http://www.demodashi.com/demo/10706.html 基上篇[TouchID 指纹解锁] ...
- android.widget.BaseAdapter调用DataSetObservable.notifyChanged/Invalidated
在android.widget.BaseAdapter类中定义了两个notifyDataXXX方法. public void notifyDataSetChanged() { mDataSet ...
- 【微信小程序】:实现轮播图3秒滚动
wxml模板:(数据一维数组) <scroll-view scroll-y="true"> <swiper autoplay="auto" i ...
- HDUOJ--点球大战
点球大战 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- 【LeetCode】39. Combination Sum (2 solutions)
Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combin ...
- WordPress网站搬家全过程 亲身体验WordPress搬家,总结几点
需要移动的文件主要是网站文件和数据库文件,如果是简单的wordpress 操作就是:备份网站文件,导出数据库文件,上传网站文件,导入数据库文件,移动网站文件,修改wordpress的wp-conf ...
- 【java设计模式】之 代理(Proxy)模式
代理模式的核心作用就是通过代理,控制对对象的访问.这跟实际中是一样的,比如说明星都有经纪人,这就是一个代理,比如有人要找某明星拍戏,那么首先处理这事的是他的经纪人,虽然拍戏需要自己拍,但是拍戏前后的一 ...