1


I have create an EJB program with 2 interfaces, 1 persistente class and 1 stateless class which implement the 2 interfaces (Remote interface and Local interface)

After that I've create a Java Client with 1 class and I add jboss-client.jar to classpath of java client app and jboss-ejb-client.properties files. But when I run the java client it's generate an error.

I need your help to fix it. Thank you.

ClientEJB.java

    package main;
    import java.util.Properties;

    import javax.naming.*;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;

    import metier.ICatalogueRemote;
    import metier.Produit;


    public class ClientEJB {
        public static void main(String[] args) {
            try{
            Properties p = new Properties();
            p.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
            Context ctx = new InitialContext(p);
            ICatalogueRemote stub = (ICatalogueRemote) ctx.lookup("ejb:/CatalogueEJB/CAT!metier.ICatalogueRemote");

            stub.addProduit(new Produit("HP",8000));
            stub.addProduit(new Produit("Clé usb ZTE", 5000));
            stub.addProduit(new Produit("HP ProBook 4700", 10000));

            }catch(NamingException ex){
                ex.printStackTrace();
            }
        }
    }

# jboss-ejb-client.properties
#
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
 remote.connection.default.host=127.0.0.1
remote.connection.default.port = 1234  
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
#remote.connection.default.username=root
#remote.connection.default.password=

ERROR MESSAGE GENERATE WHEN I RUN THE APPLICATION

   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)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at main.ClientEJB.main(ClientEJB.java:18)
Federico Sierra
  • 5,118
  • 2
  • 23
  • 36
  • Take a look in this question, maybe can help you. http://stackoverflow.com/questions/6387238/what-does-javax-naming-noinitialcontextexception-mean – Federico Sierra Nov 28 '14 at 12:41

1 Answers1

1

you need one more jndi.properties file including below code

java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
java.naming.provider.url=remote://cie-pftestvm2:4447
java.naming.security.principal=jmstest
java.naming.security.credentials=admin@123
xiyurui
  • 225
  • 3
  • 4