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

本文详细介绍了在使用JBoss服务器部署应用时遇到的Java.lang.NoClassDefFoundError问题,特别是与com/sun/image/codec/jpeg/JPEGCodec类相关的问题。文章提供了解决方案,包括修改模块XML文件来引入缺失的类路径,从而解决运行时错误。通过此解决方案,开发者可以避免在多环境切换或部署到新服务器时遇到此类问题。

验证码在本地环境显示正常,上传到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.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值