2
I’m trying to make a simple EJB, followed some tutorials, analyzed the Wildfly sample code, and yet, I’m facing an error.
Could someone help me?
The mistake:
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:
My EJB:
The structure of my project:
The Log of the Wildfly:
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 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);
}
Rename
ClientAdder.properties
forjboss-ejb-client.properties
and ensure that this file is inside the generated jar (e.g., if your project is Maven put the file inside the foldersrc/main/resources
. Also ensure thatjboss-client.jar
is in the client’s classpath.– Anthony Accioly
Thanks for the help, yes, those were two problems, another problem is that I noticed that there were missing wildfly libraries on the client side.
– danilo
now that I’ve noticed, that’s right, just add this library
jboss-client.jar
and in the draft resolution, in my version: https://mvnrepository.com/artifact/org.wildfly/wildfly-client-all/9.0.1.Final– danilo