JBoss Community

ejb client and naming error - problem

created by Dariusz Kominek in EJB3 - View the full discussion

I'm very beginner in ejb programming so please don't be angry if the question is easy.

Below is a code I wrote and it produces an error. What should I change to get this to work? I work with Eclipse Juno and JBoss 7.1.1. Below example should work for

Application Server - JBoss 4.2.2 GA

IDE - Eclipse 3.4.1

It doesn't work for my environment. Any help will be appreciated.

 

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(NamingManager.java:674)

at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)

at javax.naming.InitialContext.init(InitialContext.java:242)

at javax.naming.InitialContext.<init>(InitialContext.java:216)

at MyBeanClient.main(MyBeanClient.java:13)

Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory

at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

at java.lang.ClassLoader.loadClass(ClassLoader.java:423)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

at java.lang.ClassLoader.loadClass(ClassLoader.java:356)

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)

... 4 more

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

IMyBean.java

 

import java.io.Serializable;

public interface IMyBean extends Serializable {

public void doSomething();

}

 

MyBeanRemote.java

 

import javax.ejb.Remote;

@Remote

public interface MyBeanRemote extends IMyBean{

}

 

MyBeanLocal.java

 

import javax.ejb.Local;

@Local

public interface MyBeanLocal extends IMyBean {

}

 

MyBean.java

 

import javax.ejb.Stateless;

@Stateless

public class MyBean implements MyBeanLocal, MyBeanRemote {

private static final long serialVersionUID = 9184424076718418234L;

public void doSomething() {

System.out.println("Hello World!");

}

}

 

MyBeanClient.java

 

import java.util.Properties;

import javax.naming.InitialContext;

import javax.naming.NamingException;

public class MyBeanClient {

public static void main(String[] args) {

try {

Properties props = new Properties();

props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");

props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");

props.setProperty("java.naming.provider.url", "127.0.0.1:1099");

 

InitialContext ctx = new InitialContext(props);

MyBeanRemote bean = (MyBeanRemote) ctx.lookup("MyBean/remote");

 

bean.doSomething();

} catch (NamingException e) {

e.printStackTrace();

}

}

}

Reply to this message by going to Community

Start a new discussion in EJB3 at Community