title: SerialInitContextFactory not found in glassfish naming
body: <p>This one starts to drive me completely nuts ...</p>
  
  <p>I want to create a Glassfish client application using Maven.</p>
  
  <p>For that, I've added the requried gf-client dependency :</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.appclient&lt;/groupId&gt;
          &lt;artifactId&gt;gf-client&lt;/artifactId&gt;
          &lt;version&gt;3.1&lt;/version&gt;
          &lt;type&gt;pom&lt;/type&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>Then, wanting to contact my Glassfish server, running on the same application, I do the usual lookup :</p>
  
  <pre><code>Properties p = new Properties();
  // optional. Defaults to localhost. Only needed if web server is running
  // on a different host than the appserver
  p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
  // optional. Defaults to 3700. Only needed if target orb port is not
  // 3700.
  p.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
  Context context = new InitialContext(p);
  // Stores the list of reachable EJBs
  return context.lookup(interfacesToNames.getProperty(className));
  </code></pre>
  
  <p>Unfortunatly, when doing so, all I get is </p>
  
  <pre><code>Caused by: javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.impl.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com/sun/enterprise/naming/impl/SerialInitContextFactory]
          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
          at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
          at javax.naming.InitialContext.init(InitialContext.java:242)
          at javax.naming.InitialContext.&lt;init&gt;(InitialContext.java:216)
          ... 6 more
  Caused by: java.lang.ClassNotFoundException: com/sun/enterprise/naming/impl/SerialInitContextFactory
          at java.lang.Class.forName0(Native Method)
          at java.lang.Class.forName(Class.java:264)
          at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:63)
          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)
          ... 9 more
  </code></pre>
  
  <p>After some checks, I've noticed that my <code>glassfish-naming-3.1.jar</code> is present in CLASSPATH for that client application. And, according to Eclipse code lookup, it is this jar that should contain <code>com.sun.enterprise.naming.impl.SerialInitContextFactory</code>. However, if in debug mode, I do <code>getClass().getClassLoader().getResource("com/sun/enterprise/naming/impl/SerialInitContextFactory")</code> it returns me null, which clearly indicates that the class can't be found.</p>
  
  <p>For more infos, the JAR is copied from my local maven repository using this plugin configuration :</p>
  
  <pre><code>        &lt;plugin&gt;
              &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;package output directory&lt;/id&gt;
                      &lt;phase&gt;package&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;copy-dependencies&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;prependGroupId&gt;true&lt;/prependGroupId&gt;
                          &lt;includeScope&gt;compile&lt;/includeScope&gt;
                          &lt;outputDirectory&gt;${dependencies.outputDir}/jars&lt;/outputDirectory&gt;
                          &lt;prefix&gt;${dependencies.outputDir}&lt;/prefix&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
  </code></pre>
  
  <p>Furthermore, I have to confess that, when running a simple test using the same API to connect to Glassfish server, there is absolutely no problem, which directs me to a ClassLoader issue.</p>
  
  <p>When running that client, the current class loader is (as denoted by <code>getClass().getClassLoader().getClass().getName()</code>) <code>sun.misc.Launcher$AppClassLoader</code>. Which unfortunatly is exactly the same than when running unit test.</p>
  
  <p>So, what can I do to solve that bug ?</p>
  
  <p><strong>EDIT</strong> Class exists in <code>glassfish-naming-3.1.jar</code>, but does not seems to be findable by standard classloader.</p>
  
  <p><strong>EDIT</strong> An interesting discovery :</p>
  
  <pre><code>getClass().getClassLoader().getResource("com/sun/enterprise/naming/impl") = jar:file:/C:/Users/pouet/pouet/target/jars/glassfish-naming-3.1.jar!/com/sun/enterprise/naming/impl
  </code></pre>
  
  <p>while </p>
  
  <pre><code>getClass().getClassLoader().getResource("com/sun/enterprise/naming/impl/SerialInitContextFactory") = null
  </code></pre>