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?
   
  

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3870515#3870515

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3870515


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to