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 ...
随机推荐
- java 中文转拼音之pinyin4j
一.简介 有时候,须要将汉字编程相应的拼音.以方便数据的处理.比方在Android手机应用的开发上.要查询联系人的姓名.通常都是用拼音进行查询的. 比方要查询"曹孟德",就能够输入 ...
- spring mvc中@requesMapping的可配置参数和标注的处理方法的可选参数
@RequestMapping的可选参数 value:表示需要匹配的url的格式. method:表示所需处理请求的http 协议(如get,post,put,delete等),可选值为Request ...
- DevExpress.XtraLayout.LayoutControl 动态添加控件
// Create an item within a specified group,// bound to a specified data field with the specified edi ...
- GPT磁盘win7激活工具
系统重装前是Win10,再次重装没有格式化磁盘.GPT分区模式安装的Win7,传统的Win7激活工具都是基于KMS的. 今天,GPT磁盘win7激活工具针对GPTwin7de激活! 01.未激活 02 ...
- 【mysql】Innodb三大特性之adaptive hash index
1.Adaptive Hash Indexes 定义 If a table fits almost entirely in main memory, the fastest way to perfor ...
- PHP开发安全问题
1.不相信表单 对于一般的Javascript前台验证,由于无法得知用户的行为,例如关闭了浏览器的javascript引擎,这样通过POST恶意数据到服务器.需要在服务器端进行验证,对每个php脚本验 ...
- 获取网站资源 getResourceAsStream
获取网站资源(重点) public void doGet(HttpServletRequest request, HttpServletResponse response)throws Servlet ...
- c:forEach标签
//varStat代表 遍历typeListDesc集合所用到的方法 <!-- stat当前迭代的第几项 --> <c:forEach var="type" it ...
- eclipse 无代码自动提示
http://blog.csdn.net/wgw335363240/article/details/6235427eclipse 无代码提示,显示No Default Proposals,Conten ...
- PMP考试终于结束了。。。
PMP考试昨天终于结束了,可以好好的先休息下了,先不管成绩了,通过这段时间的学习了解,发现PMP在实际工作中的运用 起的作用还很大,看样子以后要学习的东西还多着呢,先休息一周再说...