title: Cast from super class with dynamic class load JAR
body: <p>I have some classes with this organisation</p>
  
  <pre><code>--&gt; : Inherit 
  
  TwittEntititesNetwork --&gt; TwitterGephiStreamer
  
  TwittGrapher          --&gt; TwitterGephiStreamer
  
  TwitterGephiStreamer is Abstract 
  TwitterGephiStreamer have a method : myMethod()
  
  Directory
      ./myApp.jar
      ./NetworkLogicDirectory/TwittGrapher.jar
      ./NetworkLogicDirectory/TwittEntititesNetwork.jar
  </code></pre>
  
  <p>I use this code to load dynamically the daughters classes (which are in another .jar file)</p>
  
  <pre><code>public static TwitterGephiStreamer LoadNetworkLogicJar() throws Exception
      {
          File dir = new File(NetworkLogicDirectory);
          URL[] urls = new URL[dir.listFiles().length];
          for(int i = 0;i &lt; dir.listFiles().length;i++)
          {
              File s = dir.listFiles()[i];
              String url  = "file:///"+s.getAbsolutePath();
              urls[i] = new URL(url);
  
          }
          ClassLoader = new URLClassLoader(urls);
  
          if(defaultProps.containsKey("NetworkLogic") &amp;&amp;  !defaultProps.getProperty("NetworkLogic").isEmpty())
          {
              Class&lt;?&gt; networkLogicClassLoader = ClassLoader.loadClass("org.naoyun.gephistream.networklogic."+defaultProps.getProperty("NetworkLogic"));
              Object object = networkLogicClassLoader.newInstance();
  
  
  
              return (TwitterGephiStreamer) object;
          }
          else
          {
              throw new Exception("blabalbalbal ");
          }
      }
  </code></pre>
  
  <p>So it's have to return a TwitterGephiStreamer which I can use as a normal class and I can use myMethod() normally .</p>
  
  <p>When I run on eclispe it's works well I don't have any error.</p>
  
  <p>When I export my app as a runnable .jar (myApp.jar) it's throw me this error : </p>
  
  <pre><code>java.lang.ClassCastException: org.naoyun.gephistream.networklogic.TwittEntitiesNetwork cannot be cast to org.naoyun.gephistream.TwitterGephiStreamer
          at org.naoyun.utils.ConfigurationTools.LoadNetworkLogicJar(ConfigurationTools.java:62)
          at org.naoyun.TwitterStreamer.&lt;init&gt;(TwitterStreamer.java:34)
          at org.naoyun.TwitterStreamer.main(TwitterStreamer.java:26)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
  </code></pre>
  
  <p>So, I don't know how to resolve this problem. Is my code creepy but Eclispe can handle it on the fly, or is there other stuff that I'm not up do date?</p>
  
  <p>Thanks for your time !</p>