0 Replies Latest reply on Mar 17, 2005 4:34 AM by 00031082

    about classloader problem?(help)

    00031082 Newbie

      I recently study <<Jboss Administration and Development 3.2>> about classloader.I change the org.jboss.chap2.ex0.ExCtx class as below:
      public class ExCtx
      {
      public static void main(String[] args) throws Exception
      {
      String filepath="D:/java_study/jboss_040811/j0.jar";

      File jar0 = new File(filepath);
      URL[] cp0 = {jar0.toURL()};
      URLClassLoader ucl0 = new URLClassLoader(cp0);
      Thread.currentThread().setContextClassLoader(ucl0);
      Class objClass = ucl0.loadClass("org.jboss.chap2.ex0.ExObj");
      Object value = objClass.newInstance();

      // Load ExCtx from j0.jar using URLClassLoader instance 1
      File jar1 = new File(filepath);
      URL[] cp1 = {jar1.toURL()};
      URLClassLoader ucl1 = new URLClassLoader(cp1);
      Thread.currentThread().setContextClassLoader(ucl1);
      Class ctxClass2 = ucl1.loadClass("org.jboss.chap2.ex0.ExCtx");
      Object ctx2 = ctxClass2.newInstance();

      try
      {
      // Invoke ExCtx[UCL1].useValue(value=ExObj[UCL0]) via reflection
      Class[] types = {Object.class};
      Method useValue = ctxClass2.getMethod("useValue", types);
      Object[] margs = {value};
      useValue.invoke(ctx2, margs);
      }
      catch(Exception e)
      {

      throw e;
      }
      }
      }

      and change the org.jboss.chap2.ex0.ExCtx class as below:
      public class ExCtx
      {
      ExObj value;

      public ExCtx() throws IOException
      {
      value = new ExObj();
      }
      public Object getValue()
      {
      return value;
      }
      public void useValue(Object obj) throws Exception
      {
      System.out.println("********************");

      ExObj ex = (ExObj) obj;
      }
      void pkgUseValue(Object obj) throws Exception
      {

      }
      }

      other classes i don't change.when I run the program,I think the running program whill throw some exceptions,but the program run right and donesn't throw exception.why?