Injection of Java class and rebind to InitialContext
julianfperez Dec 30, 2015 4:34 AMI try to rebind a java class called SomeProcess to the JNDI. This binding happens inside a singleton bean called ResourceBinder.
InitialContext ctx = new InitialContext();
ctx.rebind("SomeProcess", new SomeProcess());
log.info(">>>>> SomeProcess bound");
Later, this class is injected inside other ejb called SomeServiceBean.
@Inject
private SomeProcess process;
However, I am getting this error:
> 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
I had tried to modify the maven pom file to include this dependency:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<manifestEntries>
<Dependencies>org.jboss.remote-naming</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
And I have also modified the `module.xml` of the module `org.jboss.remote-naming` in WildFly 10 release.
<module xmlns="urn:jboss:module:1.3" name="org.jboss.remote-naming">
<resources>
<resource-root path="jboss-remote-naming-2.0.4.Final.jar"/>
<resource-root path="de/brockhaus/userMgmt/control/process"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="org.jboss.ejb-client" optional="true"/>
<module name="org.jboss.remoting"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.marshalling"/>
<module name="org.jboss.marshalling.river"/>
</dependencies>
</module>
But all this does not work.