title: ClassCast Exception when trying to Instatiate For same appModule Class
body: <p>i'm trying to instantiate AppModule Programmatically</p>
  
  <p>but i  get classCastException  </p>
  
  <p>that a DefaultContext is proper for this use. Memory leaks and/or unexpected behaviour may occur if the automatic initialization is
   performed improperly. This message may be avoided by performing
   initADFContext before using getCurrent().></p>
  
  <blockquote>
    <p>java.lang.ClassCastException: com.oracle.ocs.adaa.model.AppModuleImpl cannot be cast to com.oracle.ocs.adaa.model.AppModuleImpl
    at com.oracle.ocs.adaa.services.TreeTraverse.postTree(TreeTraverse.java:53)
                at com.oracle.ocs.adaa.restwebservice.Client.postStrategyTree(Client.java:35)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:498)
                at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
                at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
                at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
                at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)
                at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
                at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
                at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
                at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
                at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
                at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
                at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
                at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
                at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
                at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
                at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
                at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
                at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
                at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)
                at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
                at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
                at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
                at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
                at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286)
                at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260)
                at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)
                at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350)
                at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
                at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
                at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:198)
                at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:244)
                at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
                at oracle.security.jps.ee.http.JpsAbsFilter$3.run(JpsAbsFilter.java:174)
                at java.security.AccessController.doPrivileged(Native Method)
                at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
                at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:650)
                at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:112)
                at oracle.security.jps.ee.http.JpsAbsFilter.doFilterInternal(JpsAbsFilter.java:292)
                at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:149)
                at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:94)
                at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
                at oracle.security.wls.filter.SSOSessionSynchronizationFilter.doFilter(SSOSessionSynchronizationFilter.java:294)
                at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
                at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:248)
                at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
                at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3706)
                at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3672)
                at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:328)
                at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
                at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
                at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
                at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2443)
                at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2291)
                at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2269)
                at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1705)
                at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1665)
                at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:272)
                at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)
                at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)
                at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)
                at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
                at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:652)
                at weblogic.work.ExecuteThread.execute(ExecuteThread.java:420)
                at weblogic.work.ExecuteThread.run(ExecuteThread.java:360)</p>
  </blockquote>
  
  <p>and this is the code </p>
  
  <pre><code>private static AppModuleImpl am = null;
  private static final String AM_CONFIG_NAME = "AppModuleLocal";
  private static final String AM_DEF_NAME =     "com.oracle.ocs.adaa.model.AppModule";
  
  public static void postTree(JSONObject json) throws Exception{
  
      am = (AppModuleImpl) Configuration.createRootApplicationModule(AM_DEF_NAME, AM_CONFIG_NAME);
      }
  </code></pre>
  
  <p>UPDATE #1 :
  When google this exception , its said because of the same class has been loaded many times by different class loaders at run time </p>
  
  <p>and my  application structure is like the following :
  1 Model Project 
  and 
  Project 1  which have model.jpr output as a dependency //
  project 2 also have model.jpr output as a dependency </p>
  
  <p>and the Ear for the application contain a war file for project 1 and a war  project 2 
  inside each war there is a .jar file for the model </p>
  
  <p>im not sure if that is the reason (by having model jar many times )
  but is there is   a way to make a shared jar for both projects ??</p>