欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

淺談兩個(gè)jar包中包含完全相同的包名和類(lèi)名的加載問(wèn)題

 更新時(shí)間:2017年09月04日 15:48:23   投稿:jingxian  
下面小編就為大家?guī)?lái)一篇淺談兩個(gè)jar包中包含完全相同的包名和類(lèi)名的加載問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

首先從表現(xiàn)層介紹,后續(xù)后深入原理。

1、先簡(jiǎn)單介紹maven如何生成jar文件方便測(cè)試

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <configuration>
     <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
     </descriptorRefs>
     <archive>
      <manifest>
       <mainClass>Main.Main</mainClass>
      </manifest>
     </archive>
    </configuration>
    <executions>
     <execution>
      <id>make-assembly</id>
      <phase>package</phase>
      <goals>
       <goal>single</goal>
      </goals>
     </execution>
    </executions>
   </plugin>
配置了一個(gè)manifest標(biāo)簽來(lái)配置Main函數(shù)的入口。然后通過(guò)如下指令來(lái)實(shí)現(xiàn)打包。
 
mvn assembly:assembly

2、自定義兩個(gè)jar包,其中包含相同包名和類(lèi)名

與export的導(dǎo)入順序有關(guān)。只會(huì)加載第一個(gè),并且運(yùn)行正常。

3、自定義jar和jdk包, 其中包含相同的包名和類(lèi)名

與export的導(dǎo)入順序有關(guān)。同樣是只會(huì)加載第一個(gè),但是如果加載自定義的jar運(yùn)行會(huì)報(bào)錯(cuò)。加載 jdk正常。

protected Class<?> loadClass(String name, boolean resolve)
  throws ClassNotFoundException
 {
  synchronized (getClassLoadingLock(name)) {
   // First, check if the class has already been loaded
   Class<?> c = findLoadedClass(name);
   if (c == null) {
    long t0 = System.nanoTime();
    try {
     if (parent != null) {
      c = parent.loadClass(name, false);
     } else {
      c = findBootstrapClassOrNull(name);
     }
    } catch (ClassNotFoundException e) {
     // ClassNotFoundException thrown if class not found
     // from the non-null parent class loader
    }
 
    if (c == null) {
     // If still not found, then invoke findClass in order
     // to find the class.
     long t1 = System.nanoTime();
     c = findClass(name);
 
     // this is the defining class loader; record the stats
     sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
     sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
     sun.misc.PerfCounter.getFindClasses().increment();
    }
   }
   if (resolve) {
    resolveClass(c);
   }
   return c;
  }
 }

4、mvn jar包沖突常用命令

mvn dependency:analyze,mvn dependency:tree

以上這篇淺談兩個(gè)jar包中包含完全相同的包名和類(lèi)名的加載問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論