I'm trying to make a simple EJB, I followed some tutorials, I looked at the Wildfly sample code, and even then, I'm facing a mistake.
Could anyone help me?
The error:
ejb:/Adder//Addition!com.labs.AdditionRemote
javax.naming.NoInitialContextException:
Need to specify class name in environment or system property,
or as an applet parameter, or in an application resource file:
java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.labs.StartCalc.main(StartCalc.java:25)
The Client Project Build Path:
MyEJB:
Thestructureofmyproject:
TheWildflyLog:
WFLYWELD0003: Processing weld deployment Adder.jar
JNDI bindings for session bean named Addition in deployment unit deployment "Adder.jar" are as follows:
java:global/Adder/Addition!com.labs.Addition
java:app/Adder/Addition!com.labs.Addition
java:module/Addition!com.labs.Addition
java:global/Adder/Addition!com.labs.AdditionRemote
java:app/Adder/Addition!com.labs.AdditionRemote
java:module/Addition!com.labs.AdditionRemote
java:jboss/exported/Adder/Addition!com.labs.AdditionRemote
ClientAdder.properties (is in the classpath):
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port = 8080
remote.connection.default.connect.
options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=ejbuser
remote.connection.default.password=EjbUser!1
AdderClient:
package com.labs;
...
public class StartCalc {
public static void main(String[] args) {
try{
Properties props = new Properties();
props.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
InitialContext context = new InitialContext(props);
String appName = "";
String moduleName = "Adder";
String distinctName = "";
String beanName = Addition.class.getSimpleName();
String interfaceName = AdditionRemote.class.getName();
String name = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + interfaceName;
AdditionRemote bean = (AdditionRemote)context.lookup(name);
Adder.jar:
package com.labs;
...
@Stateless
@LocalBean
public class Addition implements AdditionRemote {
public Addition() {
}
public int add(int a,int b){
int r=a+b;
return r;
}
}
package com.labs;
import javax.ejb.Remote;
@Remote
public interface AdditionRemote {
public int add(int a , int b);
}