我打包了一个EAR(myear.ear)文件,并将其部署在JBoss EAP 6(即JBoss 7 :)中。
看起来像这样:

lib/
  my-common.jar (Custom library containing common classes used by both the WAR and BIZ)
  --- (other libraries used by both WAR and BIZ) ---
META-INF/
    jboss-deployment-structure.xml (specifies just <ear-subdeployments-isolated>false</ear-subdeployments-isolated> )
my-biz.jar (EJB Module)
    META-INF/
        beans.xml
        MANIFEST.MF
    -- java classes --
my-war.war (WAR Module)
    WEB-INF/
        beans.xml
        lib/ (empty! I made a skinny war)
    META-INF/
        MANIFEST.MF
    resources/
    -- java classes --


my-war.war中有一个类,该类从my-common.jar中的类调用方法。这是发生了什么:

public class MyWarMember implements Serializable{//my-war.war

  public void foo(){
    MyCommonMember.deepCopy(this);
  }
}
---------------------------------------------------------------------
public class MyCommonMember{//my-common.jar
  public static Object deepCopy(Serializable obj){

    ObjectOutputStream oos .....
    ...
    oos.writeObject(obj);
    ....
    ObjectInputStream ois ....;
    ....
    ois.readObject();
  }
}


调用ois.readObject();将为MyWarMember抛出ClassNotFoundException:

java.lang.ClassNotFoundException: my.war.MyWarMember from [Module "deployment.myear.ear:main" from Service Module Loader]


您将如何解决?谢谢!

最佳答案

您已经在my-war.war和普通jar my-common.jar之间创建了循环依赖关系。


MyWarMember您正在调用

MyCommonMember.deepCopy(this);-这将起作用,因为您已将jar添加到lib中
MyCommomMember中,您正在执行

public static Object deepCopy(Serializable obj){-未找到类异常,因为它不知道您在MyWarMember中的my-war.war


解:
删除您的循环依赖项。

希望能帮助到你。

10-04 22:27
查看更多