JBoss的7和java.lang.NoClassDefFoundError:com/sun/image/codec/jpeg/JPEGCodec

验证码在本地环境显示正常,上传到jboss服务器后报错java.lang.NoClassDefFoundError:com/sun/image/codec/jpeg/JPEGCodec

参考一篇文章:http://www.derrickwilliams.com/?p=56

So you’re tooling along and make a change to your development environment or deploy to a new server, then you suddenly hit on a stacktrace like this:

Caused by: java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/JPEGCodec
        at com.aspose.pdf.kit.n.a(Unknown Source) [aspose-pdf-kit-4.3.0.jar:]
        at com.aspose.pdf.kit.PdfConverter.doConvert(Unknown Source) [aspose-pdf-kit-4.3.0.jar:]
        at com.ity.ityweb.util.FileUploadController.copyFile(FileUploadController.java:77) [ITYWeb-ejb.jar:]
        at com.ity.ityweb.util.FileUploadController.handleFileUpload(FileUploadController.java:41) [ITYWeb-ejb.jar:]
        ... 67 more
Caused by: java.lang.ClassNotFoundException: com.sun.image.codec.jpeg.JPEGCodec from [Module "deployment.ITYWeb-ear.ear:main" from Service Module Loader]
        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
        ... 71 more

 

Changing your runtime environment (to Java 7, for example) is a good way to cause this. 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. Cold comfort if you are using libraries that you have no control over and can’t do the conversion and re-build them. The quick way to resolve this runtime error in JBoss is to put an entry in the /modules/sun/jdk/main/module.xml file:


    
        
        
    
    
        
            
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
            
            
                
                    
                
            
        
    

Note the line path name=”com/sun/image/codec/jpeg” added to the subtree.

Your stacktrace regarding the com/sun/image/codec/jpeg/JPEGCodec error will be resolved and you will go on your merry way in your deployment.

你可能感兴趣的:(Java)