验证码在本地环境显示正常,上传到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 <JBoss-install-diectory>/modules/sun/jdk/main/module.xml file:
<module xmlns="urn:jboss:module:1.1" name="sun.jdk">
<resources>
<!-- currently jboss modules has not way of importing services from
classes.jar so we duplicate them here -->
<resource-root path="service-loader-resources"/>
</resources>
<dependencies>
<system export="true">
<paths>
<path name="com/sun/script/javascript"/>
<path name="com/sun/jndi/dns"/>
<path name="com/sun/jndi/ldap"/>
<path name="com/sun/jndi/url"/>
<path name="com/sun/jndi/url/dns"/>
<path name="com/sun/security/auth"/>
<path name="com/sun/security/auth/login"/>
<path name="com/sun/security/auth/module"/>
<path name="sun/misc"/>
<path name="sun/io"/>
<path name="sun/nio"/>
<path name="sun/nio/ch"/>
<path name="sun/security"/>
<path name="sun/security/krb5"/>
<path name="sun/util"/>
<path name="sun/util/calendar"/>
<path name="sun/util/locale"/>
<path name="sun/security/provider"/>
<path name="META-INF/services"/>
<path name="com/sun/image/codec/jpeg"/>
</paths>
<exports>
<include-set>
<path name="META-INF/services"/>
</include-set>
</exports>
</system>
</dependencies>
</module>
Note the line path name=”com/sun/image/codec/jpeg” added to the <paths> 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.
本文详细介绍了在使用JBoss服务器部署应用时遇到的Java.lang.NoClassDefFoundError问题,特别是与com/sun/image/codec/jpeg/JPEGCodec类相关的问题。文章提供了解决方案,包括修改模块XML文件来引入缺失的类路径,从而解决运行时错误。通过此解决方案,开发者可以避免在多环境切换或部署到新服务器时遇到此类问题。
1万+

被折叠的 条评论
为什么被折叠?



