At first I want to inform that I know this is a common problem and I have gone through the previous solutions. But none is working.
I just want to create a HelloWorld application in EJB 3.0 using eclipse & jboss 7.1.1 Final.
Here is my bean:
package com.tcs.HelloWorldPack;
import javax.ejb.Stateless;
/**
* Session Bean implementation class HelloWorld
*/
@Stateless(mappedName="HelloWorldBean")
public class HelloWorld implements HelloWorldRemote {
/**
* Default constructor.
*/
public HelloWorld() {
// TODO Auto-generated constructor stub
}
@Override
public void displayMsg() {
// TODO Auto-generated method stub
System.out.println("Hello World!!");
}
}
Here is my remote interface:
package com.tcs.HelloWorldPack;
import javax.ejb.Local;
//import javax.ejb.Remote;
import javax.ejb.Remote;
@Remote
public interface HelloWorldRemote {
void displayMsg();
}
Here is my client:
package com.tcs.HelloWorldClient;
import java.util.Properties;
import com.tcs.HelloWorldPack.*;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class HelloWorldClient {
private static final String LOOKUP_STRING = "HelloWorldBean";
/*
* location of JBoss JNDI Service provider the client will use. It should be
* URL string.
*/
private static final String PROVIDER_URL = "jnp://localhost:1099";
/*s
* specifying the list of package prefixes to use when loading in URL
* context factories. colon separated
*/
private static final String JNP_INTERFACES = "org.jboss.naming:org.jnp.interfaces";
/*
* Factory that creates initial context objects. fully qualified class name.
*/
private static final String INITIAL_CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory";
private static Context initialContext;
public static void main(String[] args) throws NamingException {
// Properties extends HashTable
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
prop.put(Context.URL_PKG_PREFIXES, JNP_INTERFACES);
prop.put(Context.PROVIDER_URL, PROVIDER_URL);
initialContext = new InitialContext(prop);
// initialContext = new InitialContext();
HelloWorldRemote hello = (HelloWorldRemote) initialContext.lookup(LOOKUP_STRING);
// @EJB HelloWorldRemote hello;
hello.displayMsg();
}
}
But I am getting this exception while running the client:
Exception in thread "main" 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 com.tcs.HelloWorldClient.HelloWorldClient.main(HelloWorldClient.java:42)
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)
... 4 more
Both the client & the bean is running in same computer. I am very new to the EJB thing. Please explain what is wrong here. Thanks in advance.