jboss & NoInitialContextException
mrf Oct 25, 2012 11:00 AMHi,
I recently started learning EJB. I was trying to follow the work book examples from the EJB 3.0 book by Bill Burke & Richard Monson-Haefel. I have an eclipse, and JBoss 7 Final configured. I was able to deploy my first stateless bean and an entity to the server, but I am not able to run the client. The exception I get is:
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at com.titan.clients.Client.getInitialContext(Client.java:37)
at com.titan.clients.Client.main(Client.java:11)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
... 6 more
The client code:
package com.titan.clients;
import javax.naming.Context;
import com.titan.domain.Cabin;
import com.titan.travelagent.TravelAgentBeanRemote;
public class Client {
public static void main(String[] args) {
try {
Context jndiContext = getInitialContext();
Object ref = jndiContext.lookup("TravelAgentBean/remote");
TravelAgentBeanRemote dao = (TravelAgentBeanRemote) ref;
Cabin cabin_1 = new Cabin();
cabin_1.setId(1);
cabin_1.setName("Master Suite");
cabin_1.setDeckLevel(1);
cabin_1.setShipId(1);
cabin_1.setBedCount(3);
dao.createCabin(cabin_1);
Cabin cabin_2 = dao.findCabin(1);
System.out.println(cabin_2.getName());
System.out.println(cabin_2.getDeckLevel());
System.out.println(cabin_2.getShipId());
System.out.println(cabin_2.getBedCount());
} catch (javax.naming.NamingException ne) {
ne.printStackTrace();
}
}
public static Context getInitialContext()
throws javax.naming.NamingException {
return new javax.naming.InitialContext();
}
}
The jndi.properties file:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost
I also tried setting the properties by injecting the constructor: new InitialContext(properties);
Sadly, to no avail...
The persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="titan">
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
</persistence>
I'll be happy to post any more files/contents, am just not sure what else can be helpful or is needed.
There are tones of similar issues on the internet, but I wasn't able to fix my issue.
Can anyone help me to sort it out?
Thanks