0

I have error while runing my Project it's correctly deployed but i have this error

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(Unknown Source)

here is my main Code :

try {
        Context context = new InitialContext();
        UserServicesRemote userservicesremote = (UserServicesRemote) context.lookup("behealthy-ear/behealthy-ejb/UserServices!services.UserServicesRemote");
    } catch (NamingException e) {
        e.printStackTrace();
    }

My canonical adress is true : enter image description here

hela
  • 51
  • 12
  • Exactly where is the snippet of code you're running? You say "main code" - is this a client application trying to connect to a remote EJB on a server? – Gimby Oct 13 '16 at 14:51
  • yes It's a client application , I'm trying to connect to my remote EJB – hela Oct 15 '16 at 15:14

3 Answers3

0

this exception (NamingException) is indicating that the name of service not is correct. When you server is deployed, you can see in the log the names of services deployed. Por example:

java:global/backend-ear/backend-ejb/UserBOEJB!org.backend.bo.UserBOLocal
java:app/backend-ejb/UserBOEJB!org.backend.bo.UserBOLocal
java:module/UserBOEJB!org.backend.bo.UserBOLocal
java:global/backend-ear/backend-ejb/UserBOEJB
java:app/backend-ejb/UserBOEJB
java:module/UserBOEJB

You can use the first line of your log (global) for the lookup.

Gaalvarez
  • 165
  • 1
  • 7
  • my JNDI name is correct , and there was the screen shot of the jndi name when i run the server . – hela Oct 15 '16 at 15:16
  • you tried the first route: context.lookup("java:global/behealthy-ear/behealthy-ejb/UserService!services.UserServicesRemote"); – Gaalvarez Oct 16 '16 at 21:35
0

Suggestion: Perhaps you should add jboss-client.jar into your client environment. ../bin/client/

0

The error is not from the actual lookup, but it can't initialise the JNDI-system properly.

When you have a standalone-client you need to add a file jndi.properties like this:

java.naming.factory.url.pkgs=org.jboss.ejb.client.naming

and a file jboss-ejb-client.properties like this:

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

You have to add jboss-client.jar to the classpath and use the correct JNDI-name in the ejb:-namespace, not the one in the java:-namespace from the logfile. It looks like this:

ejb:backend-ear/backend-ejb/UserBOEJB!org.backend.bo.UserBOLocal
Erhard Siegl
  • 557
  • 2
  • 8