来源:weblogic 类加载机制日积月累,慢慢消化 作者:夏德虎

 

 

</p>

文章引用1:classloader机制概述,引用自:CSDN

<span style="color:rgb(0,0,0);line-height:1.5;">JVM在运行时会产生三个ClassLoader,Bootstrap ClassLoader、Extension ClassLoader和AppClassLoader<span style="color:rgb(0,0,204);line-height:1.5;">.</span>其中,Bootstrap是用C<span style="color:rgb(0,0,204);line-height:1.5;">+</span><span style="color:rgb(0,0,204);line-height:1.5;">+</span>编写的,我们在Java中看不到它,是null。它用来加载核心类库,在JVM源代码中这样写道:<span class="Apple-converted-space"> </span> <br /><span style="color:rgb(0,0,255);line-height:1.5;">static</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,255);line-height:1.5;">const</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,255);line-height:1.5;">char</span><span class="Apple-converted-space"> </span>classpathFormat<span style="color:rgb(0,0,204);line-height:1.5;">[</span><span style="color:rgb(0,0,204);line-height:1.5;">]</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,0,255);line-height:1.5;">"%/lib/rt.jar: "</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,0,255);line-height:1.5;">"%/lib/i18n.jar: "</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,0,255);line-height:1.5;">"%/lib/sunrsasign.jar: "</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,0,255);line-height:1.5;">"%/lib/jsse.jar: "</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,0,255);line-height:1.5;">"%/lib/jce.jar: "</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,0,255);line-height:1.5;">"%/lib/charsets.jar: "</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,0,255);line-height:1.5;">"%/classes "</span><span style="color:rgb(0,0,204);line-height:1.5;">;</span><span class="Apple-converted-space"> </span> <br />知道为什么不需要在classpath中加载这些类了吧?人家在JVM启动的时候就自动加载了,并且在运行过程中根本不能修改Bootstrap加载路径。<span class="Apple-converted-space"> </span> <br />Extension ClassLoader用来加载扩展类,即<span style="color:rgb(0,0,204);line-height:1.5;">/</span>lib<span style="color:rgb(0,0,204);line-height:1.5;">/</span>ext中的类。<span class="Apple-converted-space"> </span> <br />最后AppClassLoader才是加载Classpath的。<span class="Apple-converted-space"> </span> <br />ClassLoader加载类用的是委托模型。即先让Parent类<span style="color:rgb(0,0,204);line-height:1.5;">(</span>而不是Super,不是继承关系<span style="color:rgb(0,0,204);line-height:1.5;">)</span>寻找,Parent找不到才自己找。看来ClassLoader还是蛮孝顺的。三者的关系为<span style="color:rgb(0,0,204);line-height:1.5;">:</span>AppClassLoader的Parent是ExtClassLoader,而ExtClassLoader的Parent为Bootstrap ClassLoader。加载一个类时,首先BootStrap先进行寻找,找不到再由ExtClassLoader寻找,最后才是AppClassLoader。<span class="Apple-converted-space"> </span> <br />为什么要设计的这么复杂呢?其中一个重要原因就是安全性。比如在Applet中,如果编写了一个java<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">lang</span><span style="color:rgb(0,0,204);line-height:1.5;">.</span>String类并具有破坏性。假如不采用这种委托机制,就会将这个具有破坏性的String加载到了用户机器上,导致破坏用户安全。但采用这种委托机制则不会出现这种情况。因为要加载java<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">lang</span><span style="color:rgb(0,0,204);line-height:1.5;">.</span>String类时,系统最终会由Bootstrap进行加载,这个具有破坏性的String永远没有机会加载。<span class="Apple-converted-space"> </span> <br />我们来看这段代码:<span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,153,0);line-height:1.5;">//A.java<span class="Apple-converted-space"> </span> <br /></span> <br /><span style="color:rgb(0,0,255);line-height:1.5;">public</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,255);line-height:1.5;">class</span><span class="Apple-converted-space"> </span>A<span style="color:rgb(0,0,204);line-height:1.5;">{</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(0,0,255);line-height:1.5;">public</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,255);line-height:1.5;">static</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,255);line-height:1.5;">void</span><span class="Apple-converted-space"> </span>main<span style="color:rgb(0,0,204);line-height:1.5;">(</span><span style="color:rgb(255,0,0);line-height:1.5;">String</span><span style="color:rgb(0,0,204);line-height:1.5;">[</span><span style="color:rgb(0,0,204);line-height:1.5;">]</span><span class="Apple-converted-space"> </span>args<span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">{</span><span class="Apple-converted-space"> </span> <br />A a<span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,255);line-height:1.5;">new</span><span class="Apple-converted-space"> </span>A<span style="color:rgb(0,0,204);line-height:1.5;">(</span><span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">;</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,0,0);line-height:1.5;">System</span><span style="color:rgb(0,0,204);line-height:1.5;">.</span>out<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">println</span><span style="color:rgb(0,0,204);line-height:1.5;">(</span><span style="color:rgb(255,0,0);line-height:1.5;">System</span><span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">getProperty</span><span style="color:rgb(0,0,204);line-height:1.5;">(</span><span class="Apple-converted-space"> </span><span style="color:rgb(255,0,255);line-height:1.5;">"java.ext.dirs "</span><span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">;</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,0,0);line-height:1.5;">System</span><span style="color:rgb(0,0,204);line-height:1.5;">.</span>out<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">println</span><span style="color:rgb(0,0,204);line-height:1.5;">(</span>a<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">getClass</span><span style="color:rgb(0,0,204);line-height:1.5;">(</span><span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">getClassLoader</span><span style="color:rgb(0,0,204);line-height:1.5;">(</span><span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">;</span><span class="Apple-converted-space"> </span> <br />B b<span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,255);line-height:1.5;">new</span><span class="Apple-converted-space"> </span>B<span style="color:rgb(0,0,204);line-height:1.5;">(</span><span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">;</span><span class="Apple-converted-space"> </span> <br />b<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">print</span><span style="color:rgb(0,0,204);line-height:1.5;">(</span><span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">;</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(0,0,204);line-height:1.5;">}</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(0,0,204);line-height:1.5;">}</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,153,0);line-height:1.5;">//B.java<span class="Apple-converted-space"> </span> <br /></span> <br /><span style="color:rgb(0,0,255);line-height:1.5;">public</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,255);line-height:1.5;">class</span><span class="Apple-converted-space"> </span>B<span style="color:rgb(0,0,204);line-height:1.5;">{</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(0,0,255);line-height:1.5;">public</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,255);line-height:1.5;">void</span><span class="Apple-converted-space"> </span><span style="color:rgb(255,0,0);line-height:1.5;">print</span><span style="color:rgb(0,0,204);line-height:1.5;">(</span><span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">{</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,0,0);line-height:1.5;">System</span><span style="color:rgb(0,0,204);line-height:1.5;">.</span>out<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">println</span><span style="color:rgb(0,0,204);line-height:1.5;">(</span><span style="color:rgb(0,0,255);line-height:1.5;">this</span><span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">getClass</span><span style="color:rgb(0,0,204);line-height:1.5;">(</span><span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">getClassLoader</span><span style="color:rgb(0,0,204);line-height:1.5;">(</span><span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">)</span><span style="color:rgb(0,0,204);line-height:1.5;">;</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(0,0,204);line-height:1.5;">}</span><span class="Apple-converted-space"> </span> <br /><span style="color:rgb(0,0,204);line-height:1.5;">}</span><span class="Apple-converted-space"> </span> <br />1、我们将它放在Classpath中,则打印出<span class="Apple-converted-space"> </span> <br />sun<span style="color:rgb(0,0,204);line-height:1.5;">.</span>misc<span style="color:rgb(0,0,204);line-height:1.5;">.</span>Launcher$AppClassLoader@92e78c<span class="Apple-converted-space"> </span> <br />sun<span style="color:rgb(0,0,204);line-height:1.5;">.</span>misc<span style="color:rgb(0,0,204);line-height:1.5;">.</span>Launcher$AppClassLoader@92e78c<span class="Apple-converted-space"> </span> <br />可见都是由AppClassLoader来加载的。<span class="Apple-converted-space"> </span> <br />2、我们将其放在<span style="color:rgb(0,0,204);line-height:1.5;">%</span>jre<span style="color:rgb(0,0,204);line-height:1.5;">%</span><span style="color:rgb(0,0,204);line-height:1.5;">/</span>lib<span style="color:rgb(0,0,204);line-height:1.5;">/</span><span style="color:rgb(255,0,0);line-height:1.5;">ext</span><span style="color:rgb(0,0,204);line-height:1.5;">/</span>classes<span style="color:rgb(0,0,204);line-height:1.5;">(</span>即ExtClassLoader的加载目录。其加载<span style="color:rgb(0,0,204);line-height:1.5;">/</span>lib<span style="color:rgb(0,0,204);line-height:1.5;">/</span>ext中的jar文件或者子目录classes中的class文件<span style="color:rgb(0,0,204);line-height:1.5;">)</span>中。则会打印出:<span class="Apple-converted-space"> </span> <br />sun<span style="color:rgb(0,0,204);line-height:1.5;">.</span>misc<span style="color:rgb(0,0,204);line-height:1.5;">.</span>Launcher$ExtClassLoader<span class="Apple-converted-space"> </span> <br />sun<span style="color:rgb(0,0,204);line-height:1.5;">.</span>misc<span style="color:rgb(0,0,204);line-height:1.5;">.</span>Launcher$ExtClassLoader<span class="Apple-converted-space"> </span> <br />3、我们将A<span style="color:rgb(0,0,204);line-height:1.5;">.</span>class放到<span style="color:rgb(0,0,204);line-height:1.5;">%</span>jre<span style="color:rgb(0,0,204);line-height:1.5;">%</span><span style="color:rgb(0,0,204);line-height:1.5;">/</span>lib<span style="color:rgb(0,0,204);line-height:1.5;">/</span><span style="color:rgb(255,0,0);line-height:1.5;">ext</span><span style="color:rgb(0,0,204);line-height:1.5;">/</span>classes中,而将B<span style="color:rgb(0,0,204);line-height:1.5;">.</span>class放到classpaht中又会怎么样呢?结果是:<span class="Apple-converted-space"> </span> <br />sun<span style="color:rgb(0,0,204);line-height:1.5;">.</span>misc<span style="color:rgb(0,0,204);line-height:1.5;">.</span>Launcher$ExtClassLoader<span class="Apple-converted-space"> </span> <br /><span style="color:rgb(255,0,0);line-height:1.5;">Exception</span><span class="Apple-converted-space"> </span><span style="color:rgb(255,0,0);line-height:1.5;">in</span><span class="Apple-converted-space"> </span><span style="color:rgb(255,0,0);line-height:1.5;">thread</span><span class="Apple-converted-space"> </span><span style="color:rgb(255,0,255);line-height:1.5;">"main "</span><span class="Apple-converted-space"> </span><span style="color:rgb(255,0,0);line-height:1.5;">java</span><span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">lang</span><span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">NoClassDefFoundError</span><span style="color:rgb(0,0,204);line-height:1.5;">:</span>B<span class="Apple-converted-space"> </span> <br />at A<span style="color:rgb(0,0,204);line-height:1.5;">.</span>main<span style="color:rgb(0,0,204);line-height:1.5;">(</span>A<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">java</span><span style="color:rgb(0,0,204);line-height:1.5;">:</span>6<span style="color:rgb(0,0,204);line-height:1.5;">)</span><span class="Apple-converted-space"> </span> <br />怎么会这样呢?这其中有一个重要的问题:A类当然是由ExtClassLoader来加载的,B类要由哪个加载呢?B类要由调用它自己的类的类加载器<span style="color:rgb(0,0,204);line-height:1.5;">(</span>真拗口<span style="color:rgb(0,0,204);line-height:1.5;">)</span>。也就是说,A调用了B,所以B由A的类加载器ExtClassLoader来加载。ExtClassLoader根据委托机制,先拜托Bootstrap加载,Bootstrap没有找到。然后它再自己寻找B类,还是没找到,所以抛出异常。ExtClassLoader不会请求AppClassLoader来加载!你可能会想:这算什么问题,我把两个类放到一起不就行了?<span class="Apple-converted-space"> </span> <br />呵呵,没这么简单。比如JDBC是核心类库,而各个数据库的JDBC驱动则是扩展类库或在classpath中定义的。所以JDBC由Bootstrap ClassLoader加载,而驱动要由AppClassLoader加载。等等,问题来了,Bootstrap不会请求AppClassLoader加载类啊。那么,他们怎么实现的呢?我就涉及到一个Context ClassLoader的问题,调用Thread<span style="color:rgb(0,0,204);line-height:1.5;">.</span>getContextClassLoader。具体我还没搞太明白,要知后事如何,请听下回分解!<span style="color:rgb(0,0,204);line-height:1.5;">(</span>啊!别拿砖</span>

文章引用2: weblogic的classloader装载策略及部署应用的目录结构

<span style="color:rgb(0,0,0);line-height:1.5;">weblogic的classloader装载策略及部署应用的目录结构1 目录结构 <br />在weblogic上要发布一个web applicate必须有下面的目录结构: <br />mywebapp <br />  <span style="color:rgb(0,0,204);line-height:1.5;">|</span>____WEB<span style="color:rgb(0,0,204);line-height:1.5;">-</span>INF <br />          <span style="color:rgb(0,0,204);line-height:1.5;">|</span>___lib<span class="Apple-converted-space"> </span><span style="color:rgb(255,153,0);line-height:1.5;">//放这个web application所需要的jar包 <br /></span> <br />          <span style="color:rgb(0,0,204);line-height:1.5;">|</span>___classes<span class="Apple-converted-space"> </span><span style="color:rgb(255,153,0);line-height:1.5;">//放class类 <br /></span> <br />          <span style="color:rgb(0,0,204);line-height:1.5;">|</span>___web<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">xml</span><span class="Apple-converted-space"> </span><span style="color:rgb(255,153,0);line-height:1.5;">//对这个web application描述 <br /></span> </p> <p>发布一个application需要有下面的目录结构: <br />myapplication <br />   <span style="color:rgb(0,0,204);line-height:1.5;">|</span>___APP<span style="color:rgb(0,0,204);line-height:1.5;">-</span>INF<span class="Apple-converted-space"> </span><span style="color:rgb(255,153,0);line-height:1.5;">//放在这个目录下的lib和classes不能实例化webapp下的类 <br /></span> <br />   <span style="color:rgb(0,0,204);line-height:1.5;">|</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,204);line-height:1.5;">|</span>___lib<span class="Apple-converted-space"> </span><span style="color:rgb(255,153,0);line-height:1.5;">//放ejb和webapp公用的jar包<span class="Apple-converted-space"> </span> <br /></span> <br />   <span style="color:rgb(0,0,204);line-height:1.5;">|</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,204);line-height:1.5;">|</span>___classes<span class="Apple-converted-space"> </span><span style="color:rgb(255,153,0);line-height:1.5;">//放ejb和webapp公用的类 <br /></span> <br />   <span style="color:rgb(0,0,204);line-height:1.5;">|</span>___META<span style="color:rgb(0,0,204);line-height:1.5;">-</span>INF <br />   <span style="color:rgb(0,0,204);line-height:1.5;">|</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,204);line-height:1.5;">|</span>__application<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">xml</span> <br />   <span style="color:rgb(0,0,204);line-height:1.5;">|</span>___mywebapp <br />   <span style="color:rgb(0,0,204);line-height:1.5;">|</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,204);line-height:1.5;">|</span>____WEB<span style="color:rgb(0,0,204);line-height:1.5;">-</span>INF <br />   <span style="color:rgb(0,0,204);line-height:1.5;">|</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,204);line-height:1.5;">|</span>___lib<span class="Apple-converted-space"> </span> <br />   <span style="color:rgb(0,0,204);line-height:1.5;">|</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,204);line-height:1.5;">|</span>___classes<span class="Apple-converted-space"> </span><span style="color:rgb(255,153,0);line-height:1.5;">//放class类 <br /></span> <br />   <span style="color:rgb(0,0,204);line-height:1.5;">|</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,204);line-height:1.5;">|</span>___web<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">xml</span> <br />   <span style="color:rgb(0,0,204);line-height:1.5;">|</span>___ejb<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span style="color:rgb(255,0,0);line-height:1.5;">jar</span><span class="Apple-converted-space"> </span><span style="color:rgb(255,153,0);line-height:1.5;">//ejb的jar包 <br /></span> <br /><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span><span style="color:rgb(0,0,204);line-height:1.5;">=</span> </p> <p>2<span class="Apple-converted-space"> </span><span style="color:rgb(255,0,0);line-height:1.5;">classloader</span> <br />classloader是分层次的,它只能加载比它层次高的类及它自身的类,同层次的类及比它层次低的类都不能加载。在weblogic中的classloader有5个层次,从高到低排: <br />a<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span class="Apple-converted-space"> </span>jdk <br />b<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span class="Apple-converted-space"> </span>jdk<span class="Apple-converted-space"> </span><span style="color:rgb(255,0,0);line-height:1.5;">ext</span> <br />c<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span class="Apple-converted-space"> </span><span style="color:rgb(255,0,0);line-height:1.5;">system</span><span class="Apple-converted-space"> </span>classpath <br />d<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,204);line-height:1.5;">(</span>APP<span style="color:rgb(0,0,204);line-height:1.5;">-</span>INF<span style="color:rgb(0,0,204);line-height:1.5;">/</span>lib<span class="Apple-converted-space"> </span><span style="color:rgb(255,0,0);line-height:1.5;">and</span><span class="Apple-converted-space"> </span>APP<span style="color:rgb(0,0,204);line-height:1.5;">-</span>INF<span style="color:rgb(0,0,204);line-height:1.5;">/</span>classes<span style="color:rgb(0,0,204);line-height:1.5;">)</span> <br />e<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span class="Apple-converted-space"> </span><span style="color:rgb(0,0,204);line-height:1.5;">(</span>WEB<span style="color:rgb(0,0,204);line-height:1.5;">-</span>INF<span style="color:rgb(0,0,204);line-height:1.5;">/</span>lib<span class="Apple-converted-space"> </span><span style="color:rgb(255,0,0);line-height:1.5;">and</span><span class="Apple-converted-space"> </span>WEB<span style="color:rgb(0,0,204);line-height:1.5;">-</span>INF<span style="color:rgb(0,0,204);line-height:1.5;">/</span>classes<span style="color:rgb(0,0,204);line-height:1.5;">)</span><span class="Apple-converted-space"> </span> <br />f<span style="color:rgb(0,0,204);line-height:1.5;">.</span><span class="Apple-converted-space"> </span>ejb<span>.</span><span style="color:rgb(255,0,0);line-height:1.5;">jar</span> <br />注意:e 和 f 的classloader是同级的。 <br />所以APP<span style="color:rgb(0,0,204);line-height:1.5;">-</span>INF<span style="color:rgb(0,0,204);line-height:1.5;">/</span>lib和APP<span style="color:rgb(0,0,204);line-height:1.5;">-</span>INF<span style="color:rgb(0,0,204);line-height:1.5;">/</span>classes下类不能实例化webapp下的类,这点尤其要注意,否则会报类找不到的错误。</span>

 
文件: WebLogic类加载过程简述.rar
大小: 177KB
下载: 下载

</span>

转载请注明:WebLogic Android 博客 » 转载-weblogic 类加载机制