今天迁移老项目到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 ...
随机推荐
-
一步步学习NHibernate(10)&mdash;&mdash;连接查询和子查询(2)
请注明转载地址:http://www.cnblogs.com/arhat 在上一章中,老魏讲述了HQL的链接查询,本章呢,老魏开始讲述HQL的子查询.子查询在SQL中也是占据着非常重要的作用,如果没有 ...
-
[置顶] operator overloading(操作符重载,运算符重载)运算符重载,浅拷贝(logical copy) ,vs, 深拷贝(physical copy)
operator overloading(操作符重载,运算符重载) 所谓重载就是重新赋予新的意义,之前我们已经学过函数重载,函数重载的要求是函数名相同,函数的参数列表不同(个数或者参数类型).操作符重 ...
-
8086 cpu为什么要把段地址*16+偏移量形成物理地址呢?
8086 cpu为什么要把段地址*16+偏移量形成物理地址呢? 这是因为,8086地址线是20位,段寄存器是16位,将段寄存器*16实际上就是向左移动4位,形成20位和8086的二十位地址线匹配. I ...
-
Android 之夜间模式(多主题)的实现
引言 夜间模式其实属于多主题切换的一种,不过是最麻烦的一种.因为在夜间模式下不仅要切换主色调,次要色调等等,还要覆盖一些特殊的颜色,因为在夜间模式下总不能什么都是黑的把,那不得丑死-.-,所以当你夜间 ...
-
java中Array/List/Map/Object与Json互相转换详解(转载)
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programming Langu ...
-
filebeat-kafka日志收集
filebeat-kafka日志收集 由于线上的logstash吃掉大量的CPU,占用较多的系统资源,就想找其它的组件替代.我们的日志需要收集并发送到kafka,生成的日志已经是需要的数据,不用过滤. ...
-
(Beta)团队贡献分
Beta阶段团队每个成员都积极响应一起完成了开发, 所以最后我们一致决定各个成员的贡献分相同. 林珣玙 53 康家华 52 张启东 51 刘彦熙 49 马瑶华 48 仇栋民 47
-
339. Nested List Weight Sum
https://leetcode.com/problems/nested-list-weight-sum/description/ Given a nested list of integers, r ...
-
sitecore系列教程之简单和个性化
现代Web开发倾向于关注内容管理系统(CMS)的功能丰富的程序.最终用户可以做什么?作为内容管理者,我们可以为最终用户实现其目标提供哪些功能?开发人员可以为内容管理员构建哪些组件来实现它们? 相关内容 ...
-
[BZOJ 3652]大新闻
[BZOJ 3652] 大新闻 题意 随机从 \([0,n)\) 中选取一个整数 \(x\), 并从 \([0,n)\) 中再选取一个整数 \(y\). 有 \(p\) 的概率选取一个能令 \(x\o ...