2 Replies Latest reply on Apr 20, 2005 12:29 PM by jameselliot

    Class Loader Issues

    jameselliot

      I am trying to load classes on the fly according to a full Java class name. I have a class loading strategy of:

      Get:

      ClassLoader threadLoader = Thread.currentThread().getContextClassLoader();
      ClassLoader callLoader = context.getCallingClass().getClassLoader();
      


      If either class loader is null, return the other one. Otherwise if one is the parent of the other use the child, otherwise try them both.


      I am having trouble with the following senario: All classes are packaged in my war file.

      I load a class using my loading strategy, which in turn loads another class using the same strategy.

      On windows this works fine, on Linux I can a ClassNotFoundException when loading the second class:

       37979 java.lang.ClassNotFoundException: No ClassLoaders found for: com.videocoding.vicop.requestQueue.handlers.wap.MediaBurst^M
       37980
       37981 at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:292)
       37982 at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:464)
       37983 at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:374)
       37984 at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
       37985 at com.videocoding.vicop.common.ClassLoaderUtils.loadClass(ClassLoaderUtils.java:68)
      


      From my logging the class loader used can be seen:

      2005-04-20 16:00:12,033 INFO [com.videocoding.vicop.common.ClassLoaderUtils] Received ClassLoader org.jboss.web.tomcat.tc5.WebCtxLoader$ENCLoader with hashcode 6115379
      


      Compare this logging to the successful class load:

      2005-04-20 16:00:12,017 DEBUG [com.videocoding.vicop.common.ClassLoaderUtils] Loading class com.videocoding.vicop.triggers.handlers.PlayerPushHandler
      2005-04-20 16:00:12,017 INFO [com.videocoding.vicop.common.ClassLoaderUtils] No common parents, returning threadLoader
      2005-04-20 16:00:12,017 INFO [com.videocoding.vicop.common.ClassLoaderUtils] Received ClassLoader org.jboss.web.tomcat.tc5.WebCtxLoader$ENCLoader with hashcode 6115379
      


      It can be seen that the same class loader is being used. When we look in the working directory we see:

      [root]# pwd
      /opt/jboss-4.0.1sp1/server/default/tmp/deploy/tmp16487vicop.war/WEB-INF/classes
      [root]# ls com/videocoding/vicop/triggers/handlers/
      AbstractHandler.class DefaultHandler.class PlayerPushHandler.class TriggerHandler.class
      [root]# ls com/videocoding/vicop/requestQueue/handlers/wap/
      MediaBurst.class WapPushHandler.class
      


      so both classes are in the same classpath directory and are using the same class loader.

      Additionally this all works on Windows. Windows set up is:
      java version "1.5.0_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
      Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)
      
      16:22:52,921 INFO [Server] Starting JBoss (MX MicroKernel)...
      16:22:52,921 INFO [Server] Release ID: JBoss [Zion] 4.0.1sp1 (build: CVSTag=JBoss_4_0_1_SP1 date=200502160314)
      


      and linux set up is

      java version "1.5.0_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
      Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)
      
      12:39:06,566 INFO [Server] Starting JBoss (MX MicroKernel)...
      12:39:06,567 INFO [Server] Release ID: JBoss [Zion] 4.0.1sp1 (build: CVSTag=JBoss_4_0_1_SP1 date=200504161944)
      


      Any ideas or places to look would be very welcome because I am just about out of ideas.

      Thank you for your time.

      James.


      I am sure this will be something daft, but for the life of me I can not work out what it is.


        • 1. Re: Class Loader Issues
          starksm64

          Explain why there is a ^M(carriage return, part of win32 \r\n eol sequence) on a linux machine log.

          • 2. Re: Class Loader Issues
            jameselliot

            Thank you.

            I thought it was just a copy and paste mess.. however when I went back and checked, it was there.

            Strange, copy and pasted the string from firefox into a form on the server. Thus it was saved like that in the database. Time to add trim to the action class.

            How much time wasted over simple mistakes and daft copy and paste errors.

            and to think I should of spotted it myself when it was so obvious, guess you don't see it until you paste it into something that will show it to you.

            at least its fixed :) Horrah..