title: Injection of Java class and rebind to InitialContext
body: <p>I try to rebind a java class called SomeProcess to the JNDI. This binding happens inside a singleton bean called ResourceBinder.</p>
  
  <pre><code>InitialContext ctx = new InitialContext();
  ctx.rebind("SomeProcess", new SomeProcess());
  log.info("&gt;&gt;&gt;&gt;&gt; SomeProcess bound");
  </code></pre>
  
  <p>Later, this class is injected inside other ejb called SomeServiceBean.</p>
  
  <pre><code>@Inject
  private SomeProcess process;
  </code></pre>
  
  <p>However, I am getting this error:</p>
  
  <blockquote>
    <p>org.jboss.naming.remote.protocol.NamingIOException: Failed to rebind
    [Root exception is java.io.IOException:
    java.lang.ClassNotFoundException:
    de.brockhaus.userMgmt.control.process.SomeProcess from [Module
    "org.jboss.remote-naming:main" from local module loader @ed17bee
    (finder: local module finder @2a33fae0 (roots: C:\Program
    Files\jboss\wildfly\modules,C:\Program
    Files\jboss\wildfly\modules\system\layers\base))]]    at
    org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:49)
    2015-12-28 20:33:02,302 DEBUG [main]
    de.brockhaus.userMgmt.util.jndi.BeanLocator: Looking up for:
    /BRO130_3_7_ResourceBinder-solution/SomeServiceBean!de.brockhaus.userMgmt.boundary.SomeService
      at
    org.jboss.naming.remote.protocol.v1.Protocol$3.execute(Protocol.java:306)
      at
    org.jboss.naming.remote.protocol.v1.Protocol$3.execute(Protocol.java:265)
      at
    org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.rebind(RemoteNamingStoreV1.java:116)
      at
    org.jboss.naming.remote.client.HaRemoteNamingStore$3.operation(HaRemoteNamingStore.java:302)
      at
    org.jboss.naming.remote.client.HaRemoteNamingStore$3.operation(HaRemoteNamingStore.java:299)
      at
    org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:137)
      at
    org.jboss.naming.remote.client.HaRemoteNamingStore.rebind(HaRemoteNamingStore.java:298)
      at
    org.jboss.naming.remote.client.RemoteContext.rebind(RemoteContext.java:163)
      at
    org.jboss.naming.remote.client.RemoteContext.rebind(RemoteContext.java:170)
      at javax.naming.InitialContext.rebind(InitialContext.java:433)  at
    de.brockhaus.userMgmt.boundary.ResourceBinder.bindResources(ResourceBinder.java:32)
      at
    de.brockhaus.userMgmt.boundary.SomeServiceTest.bindResources(SomeServiceTest.java:21)
      at
    de.brockhaus.userMgmt.boundary.SomeServiceTest.main(SomeServiceTest.java:13)
    Caused by: java.io.IOException: java.lang.ClassNotFoundException:
    de.brockhaus.userMgmt.control.process.SomeProcess from [Module
    "org.jboss.remote-naming:main" from local module loader @ed17bee
    (finder: local module finder @2a33fae0 (roots: C:\Program
    Files\jboss\wildfly\modules,C:\Program
    Files\jboss\wildfly\modules\system\layers\base))]     at
    org.jboss.naming.remote.protocol.v1.Protocol$3.handleServerMessage(Protocol.java:329)
      at
    org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
      at
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745) Caused by:
    java.lang.ClassNotFoundException:
    de.brockhaus.userMgmt.control.process.SomeProcess from [Module
    "org.jboss.remote-naming:main" from local module loader @ed17bee
    (finder: local module finder @2a33fae0 (roots: C:\Program
    Files\jboss\wildfly\modules,C:\Program
    Files\jboss\wildfly\modules\system\layers\base))]     at
    org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
      at
    org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
      at
    org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
      at
    org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
      at
    org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
      at java.lang.Class.forName0(Native Method)  at
    java.lang.Class.forName(Class.java:348)   at
    org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:131)
      at
    org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:112)
      at
    org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:948)
      at
    org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1255)
      at
    org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
      at
    org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
      at
    org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
      at
    org.jboss.naming.remote.protocol.v1.Protocol$3.handleServerMessage(Protocol.java:327)
      ... 4 more</p>
  </blockquote>
  
  <p>In order to solve it, I have created a wilfly module de.brockhaus.userMgmt where I have put the maven build jar. This is the module.xml content
  </p>
  
  <pre><code>&lt;properties&gt;
      &lt;property name="jboss.api" value="private"/&gt;
  &lt;/properties&gt;
  
  &lt;resources&gt;
      &lt;resource-root path="BRO130_3_7_ResourceBinder-solution.jar"/&gt;
  &lt;/resources&gt;
  
  &lt;dependencies&gt;
      &lt;module name="org.apache.log4j"/&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>
  I have modified the <code>module.xml</code> of the module <code>org.jboss.remote-naming</code> in WildFly 10 release.</p>
  
  <pre><code>&lt;module xmlns="urn:jboss:module:1.3" name="org.jboss.remote-naming"&gt;
      &lt;resources&gt;
          &lt;resource-root path="jboss-remote-naming-2.0.4.Final.jar"/&gt;
      &lt;/resources&gt;
      &lt;dependencies&gt;
          &lt;module name="javax.api"/&gt;
          &lt;module name="org.jboss.ejb-client" optional="true"/&gt;
          &lt;module name="org.jboss.remoting"/&gt;
          &lt;module name="org.jboss.logging"/&gt;
          &lt;module name="org.jboss.marshalling"/&gt;
          &lt;module name="org.jboss.marshalling.river"/&gt;
          &lt;module name="de.brockhaus.userMgmt"/&gt;
      &lt;/dependencies&gt;
  &lt;/module&gt;
  </code></pre>
  
  <p>But now the problem is different: 13:36:01,016 ERROR</p>
  
  <blockquote>
    <p>[org.jboss.as.naming] (pool-1-thread-1) WFLYNAM0008: Unexpected
    internal error: java.lang.UnsupportedOperationException: WFLYNAM0043:
    Naming context is read-only   at
    org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:161)
      at
    org.jboss.as.naming.WritableServiceBasedNamingStore.rebind(WritableServiceBasedNamingStore.java:109)
      at org.jboss.as.naming.NamingContext.rebind(NamingContext.java:301)
      at
    org.jboss.naming.remote.protocol.v1.Protocol$3.handleServerMessage(Protocol.java:335)
      at
    org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
      at
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)</p>
    
    <p>13:36:01,459 ERROR [org.jboss.as.naming] (pool-1-thread-2)
    WFLYNAM0008: Unexpected internal error:
    java.lang.UnsupportedOperationException: WFLYNAM0043: Naming context
    is read-only  at
    org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:161)
      at
    org.jboss.as.naming.WritableServiceBasedNamingStore.rebind(WritableServiceBasedNamingStore.java:109)
      at org.jboss.as.naming.NamingContext.rebind(NamingContext.java:301)
      at
    org.jboss.naming.remote.protocol.v1.Protocol$3.handleServerMessage(Protocol.java:335)
      at
    org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
      at
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)</p>
    
    <p>13:36:01,590 INFO  [org.jboss.ejb.client] (pool-1-thread-3) JBoss EJB
    Client version 2.1.3.Final 13:36:01,918 ERROR [stderr] (EJB default -
    1) log4j:WARN No appenders could be found for logger
    (de.brockhaus.userMgmt.control.activity.StepOne).</p>
    
    <p>13:36:01,920 ERROR [stderr] (EJB default - 1) log4j:WARN Please
    initialize the log4j system properly.</p>
    
    <p>13:36:01,921 ERROR [stderr] (EJB default - 1) log4j:WARN See
    <a href="http://logging.apache.org/log4j/1.2/faq.html#noconfig" rel="nofollow">http://logging.apache.org/log4j/1.2/faq.html#noconfig</a> for more info.</p>
  </blockquote>