Discussions

General J2EE: Urgent! Serious problem with J2EE Classloader!

  1. Hi all,
    I'm having a serious problem with j2ee Classloading.
    I have "inherited" a J2EE application where all business classes (invoked by the EJB) are placed in the Application's Server classpath (Weblogic 8.1.4).

    Very bad because every time a class is changed the a.s. must be restarted.

    So I re-enginereed the package putting the business classes in a jar that is referenced by the EJB's MANIFEST file.

    This way all the classes would be loaded by the EJB classloader and no need to start/stop weblogic.

    Unfortunately it's not such !! I discovered that all business classes are loaded via REFLECTION


              Object objCommand = objClass.newInstance();
     
              Object[] param = new Object[1];
              param[0] = aDataContainer;
     
              objDataContainerReturn = (DataContainer) objMethod.invoke(objCommand,param);


    and the application server cannot find them using the standard J2EE Classloader mechanism.

    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at irma.business.Dispatcher.callService(Dispatcher.java:70)
    ..............
    Caused by: java.lang.NoClassDefFoundError: irma/utility/log/LogPrintStream
    at irma.business.service.LoginService.login(LoginService.java:79)


    On the other hand they're found if I put the classes on the application server classpath.

    Has anybody got advice for this ? Should I refactor the application giving up reflection ?
    Thanks a lot in advance.
  2. You have placed the jar files in the EAR file, right? They must be in the root of the EAR directory when the file has been unpacked (at least on other application servers).

    You could make a test without reflection, but I'm not so sure that it would work better. It may be that the class actually is not there.

    It could also be another error. For example a class may refer to an external resource when it is loaded and the external resource may not be found. That would give the same error. For example a configuration file or a system library. Or a class could refer to yet another jar that must be added to the manifest as well.

    Good luck!
  3. Mr.
    There is no way that the classes are reloaded by themselves when you place the jar files in JVM classpath. Your class loader policy's are in picture and every time these classes are changed and the jar is updated you have to recycle the server. Did you use ws.ext.dirs ??? Also iam not aware of any reload intervels for such things.
  4. Iam sorry i would have completely read your message. Its weblogic!! ws.ext.dirs is not relative. Well if you have created any server , specify these jar under that server class path so you can recycle only that server not the whole Application server.