java.io.InvalidClassException

本文介绍了解决EJB客户端和服务端因dom4j版本不一致导致的InvalidClassException错误的方法。通过替换jboss中的dom4j.jar文件,并提供了一个名为FindClass的工具用于查找指定类所在的jar文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

调用EJB时出错:
java.io.InvalidClassException: org.dom4j.tree.AbstractNode; local class incompatible: stream classdesc serialVersionUID = 4436254242831845461, local class serialVersionUID = 4188621179618565246
解决:
这个问题出现的原因是ejb客户端和服务端使用的dom4j版本不一致造成的,问题在于如何找到jboss中的dom4j.jar,经查找在C:/jboss-4.0.4.GA/lib目录下有一个dom4j.jar,将该文件换成ear中使用的dom4j-full.jar即可,注意必须重命名为dom4j.jar。
本例通过查找dom4j就可以找到dom4j.jar文件,如果该dom4j.jar名字不明显则找起来就费劲了,所以需要使用工具去找,从网上搜索到一个FindClass.java类实现了从某个目录下查找class文件所在的jar文件的功能,代码如下:
 

import java.util.*;

import java.io.*;

/** 
 *   <p>在本地磁盘的jar文件中寻找自己所需要的class</p> 
 *   <p>用法,只需要提供本地磁盘路径和所需要的class的全称(包括package等信息)</p> 
 *   <p>例如   org.w3c.dom.Document</p> 
 *   <p>Copyright:   Copyright   (c)Sinocomm   2002</p> 
 *   
@author   Gameboy999 
 *   
@version   1.0 
 
*/

public class FindClass {

    
public static int count = 0;

    
public FindClass() {
    }


    
private static void FindClassInLocalSystem(String path, String classname) {
        
if (path.charAt(path.length() - 1!= '/')
            path 
+= '/';
        File file 
= new File(path);
        
if (!file.exists()) {
            System.out
                    .println(
"--------------------------------------------------------");
            System.out
                    .println(
"error:   Path   not   Existed!   Please   Check   it   out!");
            System.out
                    .println(
"--------------------------------------------------------");
            
return;
        }

        String[] filelist 
= file.list();
        
for (int i = 0; i < filelist.length; i++{
            File temp 
= new File(path + filelist[i]);
            
if ((temp.isDirectory() && !temp.isHidden() && temp.exists())) {
                FindClassInLocalSystem(path 
+ filelist[i], classname);
            }
 else {
                
if (filelist[i].endsWith("jar")) {
                    
try {
                        java.util.jar.JarFile jarfile 
= new java.util.jar.JarFile(
                                path 
+ filelist[i]);
                        
for (Enumeration e = jarfile.entries(); e
                                .hasMoreElements();) 
{
                            String name 
= e.nextElement().toString();
                            
if (name.equals(classname)) {
                                System.out
                                        .println(
"--------------------------------------------------------");
                                System.out.println(
"No." + ++FindClass.count);
                                System.out.println(
"jar   package:" + path
                                        
+ filelist[i]);
                                System.out.println(name);
                                System.out
                                        .println(
"--------------------------------------------------------");
                            }

                        }

                    }
 catch (Exception eee) {
                    }

                }

            }

        }


    }


    
static public void main(String[] args) {
        
if (args.length < 2{
            System.out.println(
"Usage:");
            System.out
                    .println(
"the   first   parameter:[path   to   find]   eg.     C:/     d:/Jbuilder       Tip:only   '/'   can   be   used   here");
            System.out
                    .println(
"the   first   parameter:[class   to   find]   eg.   org.w3c.dom.Document");
            
return;
        }

        String absoluteclassname 
= args[1].replace('.''/'+ ".class";

        System.out.println(
"Find   class   [" + args[1+ "]   in   path   ["
                
+ args[0+ "]   results:");
        FindClassInLocalSystem(args[
0], absoluteclassname);
        
if (FindClass.count == 0{
            System.out
                    .println(
"--------------------------------------------------------");
            System.out.println(
"Sorry,No   such   Jar!");
            System.out
                    .println(
"--------------------------------------------------------");
        }

        System.out.println(
"Find   Process   Ended!   Total   Results:"
                
+ FindClass.count);
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值