[jboss-user] [EJB3] - ejb client and naming error - problem

Dariusz Kominek do-not-reply at jboss.com
Thu Nov 15 16:32:07 EST 2012


Dariusz Kominek [https://community.jboss.org/people/darisz] created the discussion

"ejb client and naming error - problem"

To view the discussion, visit: https://community.jboss.org/message/776774#776774

--------------------------------------------------------------
*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
[https://community.jboss.org/message/776774#776774]

Start a new discussion in EJB3 at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20121115/723762e8/attachment.html 


More information about the jboss-user mailing list