Exception in thread "main" javax.naming.NoInitialContextException: Need to

Hey,
I am exploring the technique 'JMS'. I found an sample code on the Internet (https://www.redhat.gl/docs/manuals/jboss/jboss-eap-4.2/doc/Server_Configuration_Guide/JMS_Examples-A_Point_To_Point_Example.html).
But unfortunately, by running the code on my local computer, I got an NoInitialContextException (Exception in thread "main" javax.naming.NoInitialContextException: Need to ...Application resource file: java.naming.factory.initial). After searching on the Internet, I discovered I need to configure some JNDI values. But, also after passing on the variables to the class by parameter (-Djava.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory), I still get the same error.
What have I forgotten? Hope someone can help. Thanks!
Tongue78.
public void setupPTP()
throws JMSException,
NamingException
InitialContext iniCtx = new InitialContext();
Object tmp = iniCtx.lookup("ConnectionFactory"); // exception occurs here..
QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
conn = qcf.createQueueConnection();
que = (Queue) iniCtx.lookup("queue/testQueue");
session = conn.createQueueSession(false,
QueueSession.AUTO_ACKNOWLEDGE);
conn.start();
....

Refer to the Sun App Server documentation.
http://docs.sun.com/source/819-0079/dgacc.htmlIt lists down the steps you need to follow.

Similar Messages

  • Exception in thread "main" javax.naming.NameNotFoundException: Unable to re

    Hi friends,
    I am running simple Client program of JMS to produce text message. I have JMSServer under JMS tab in weblogic home site.my desnation is topic its name is topic2.Following Error occurs
    C:\j2sdk1.4.2_12\bin>java Client1
    Exception in thread "main" javax.naming.NameNotFoundException: Unable to resolve
    'topic1' Resolved [Root exception is javax.naming.NameNotFoundException: Unabl
    e to resolve 'topic1' Resolved ]; remaining name 'topic1'
    at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.j
    ava:108)
    at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteR
    ef.java:284)
    at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteR
    ef.java:244)
    at weblogic.jndi.internal.ServerNamingNode_813_WLStub.lookup(Unknown Sou
    rce)
    at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:369)
    at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:357)
    at javax.naming.InitialContext.lookup(InitialContext.java:347)
    at Client1.main(Client1.java:21)
    Caused by: javax.naming.NameNotFoundException: Unable to resolve 'topic1' Resolv
    ed
    at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(Basic
    NamingNode.java:897)
    at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.jav
    a:230)
    at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.j
    ava:154)
    at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:18
    8)
    at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:477)
    at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
    ef.java:108)
    at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:420)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
    dSubject.java:363)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
    144)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
    a:415)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
    .java:30)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
    C:\j2sdk1.4.2_12\bin>

    I am no expert to this but, I have gotten that error when I try to subscribe to a topic that does not exist.
    Make sure your server is running and that the topic exists.

  • Javax.naming.NoInitialContextException: Need to specify class name...

    Hello,
    I am trying to use a Database Connection Pool.
    Here is the test class am using to verify the connection pool:
    public static void main(String[] args) { Connection connection = null; try { InitialContext initialContext = new InitialContext(); DataSource dataSource = (DataSource)initialContext.lookup("jdbc/<alias>"); connection= dataSource.getConnection(); } catch (SQLException e) { //   TODO Auto-generated catch block e.printStackTrace(); } catch (NamingException e) { //   TODO Auto-generated catch block e.printStackTrace(); } Statement stmt = null; try { String query = ""; stmt = connection.createStatement(); ResultSet resultSet = null; query = "SELECT <column> ...'"; resultSet = stmt.executeQuery(query); while(resultSet.next()){ System.out.println(resultSet.getString(<column>)); } stmt.close();   stmt = null; connection.close(); connection = null; } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }finally{ if (stmt != null) {   try {   stmt.close();   } catch (SQLException sqlex) {   // ignore -- as we can't do anything about it here   }   stmt = null;   }   if (connection != null) {   try { connection.close();   } catch (SQLException sqlex) {   // ignore -- as we can't do anything about it here   } connection = null;   } } }
    I get following exception..
    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:640) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243) at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280) at javax.naming.InitialContext.lookup(InitialContext.java:347) at com.internal.test.TestRun.main(TestRun.java:53) java.lang.NullPointerException at com.internal.test.TestRun.main(TestRun.java:66) Exception in thread "main"
    The exception points to
    DataSource dataSource = (DataSource)initialContext.lookup("jdbc/OrderStatus");
    Is this the correct way to test...?
    Thanks
    Srinivas

    java_2006 wrote:
    You can't access a jdbc pool like that (simply with a main method).
    The Database connection pool must be managed by a container (a servlet or application server) like tomcat.
    That is not entirely true but it certainly helps and is generally the only way it is used anyway so one might as well do it.

  • Exception in thread "main" javax.mail.MessagingException: [EOF]

    hi i have a new Application which i need to send Email from it to people
    i have tried the code in my university pc's and i works soo fine...but in my home
    it gave my error
    here is the code
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    public class TestMail
         public static void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
             boolean debug = false;
              //Set the host smtp address
              Properties props = new Properties();
              props.put("mail.smtp.host", "mx2.hotmail.com");
             // create some properties and get the default Session
             Session session = Session.getDefaultInstance(props, null);
             session.setDebug(debug);
             // create a message
                  Message msg = new MimeMessage(session);
             // set the from and to address
             InternetAddress addressFrom = new InternetAddress(from);
             msg.setFrom(addressFrom);
             InternetAddress[] addressTo = new InternetAddress[recipients.length];
             for (int i = 0; i < recipients.length; i++)
                 addressTo[i] = new InternetAddress(recipients);
         msg.setRecipients(Message.RecipientType.TO, addressTo);
         // Optional : You can also set your custom headers in the Email if you Want
         msg.addHeader("MyHeaderName", "myHeaderValue");
         // Setting the Subject and Content Type
         msg.setSubject(subject);
         msg.setContent(message, "text/plain");
         Transport.send(msg);
         public static void main(String args[])throws MessagingException
              String mailers[] = new String[1];
              mailers[0] = "[email protected]";
              postMail(mailers,"hello","hello my dear ay","[email protected]");
    }and  here is the output of the programe(the error)Exception in thread "main" javax.mail.MessagingException: [EOF]
    at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1
    512)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
    at javax.mail.Transport.send0(Transport.java:189)
    at javax.mail.Transport.send(Transport.java:118)
    at TestMail.postMail(TestMail.java:39)
    at TestMail.main(TestMail.java:45)
    Press any key to continue . . .plz help meee
    Edited by: mld on Dec 30, 2007 9:37 AM
    Edited by: mld on Dec 31, 2007 2:32 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    i have tried every thing
    i put stmp.bebug in my code and it gave me the following (tis is a part of the output...the other is not important)
    DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
    DEBUG: !anyLoaded
    DEBUG: not loading resource: /META-INF/javamail.address.map
    DEBUG: not loading file: C:\Program Files\Java\jdk1.5.0_06\jre\lib\javamail.addr
    ess.map
    DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_06\jre\lib\
    javamail.address.map (The system cannot find the file specified)
    Exception in thread "main" javax.mail.MessagingException: [EOF]
            at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
            at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1
    512)
            at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
            at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
            at javax.mail.Transport.send0(Transport.java:189)
            at javax.mail.Transport.send(Transport.java:118)
            at TestMail.postMail(TestMail.java:43)
            at TestMail.main(TestMail.java:49)
    Press any key to continue . . .

  • Exception in thread "main" javax.mail.NoSuchProviderException: invalid prov

    HI,
    I am trying to read mails from my inbox i amgetting the ErrorC:\javamail>java
    Readmail
    Exception in thread "main" javax.mail.NoSuchProviderException: No provider for IMAP
            at javax.mail.Session.getProvider(Session.java:455)
            at javax.mail.Session.getStore(Session.java:530)
            at javax.mail.Session.getStore(Session.java:510)
            at Readmail.main(Readmail.java:24)My Code is    {
    String host = "hostname";
    String username = "user";
    String password = "password";
    // Create empty properties
    Properties props = new Properties();
    // Get session
    Session session = Session.getDefaultInstance(props,null);
    // Get the store
    Store store = session.getStore("IMAP");
    store.connect(host, username, password);
    // Get folder
    Folder folder = store.getFolder("Inbox");
    folder.open(Folder.READ_ONLY);
    // Get directory
    Message message[] = folder.getMessages();
    for (int i=0, n=message.length; i<n; i++)
       System.out.println(i + ": " + message.getFrom()[0]
    + "\t" + message[i].getSubject());
    // Close connection
    folder.close(false);
    store.close();
    I have also tried POP3 and MIME and SMTP
    Can anyone help me Thanks

    hi bshannon,
    I am getting the same error for others but for pop3 the error is as below
    Exception in thread "main" javax.mail.MessagingException: Connect failed;
      nested exception is:
            java.net.ConnectException: Connection refused: connect
            at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148)
            at javax.mail.Service.connect(Service.java:275)
            at javax.mail.Service.connect(Service.java:156)
            at Readmail.main(Readmail.java:25)
    Caused by: java.net.ConnectException: Connection refused: connect
            at java.net.PlainSocketImpl.socketConnect(Native Method)
            at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
            at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
            at java.net.Socket.connect(Socket.java:452)
            at java.net.Socket.connect(Socket.java:402)
            at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
            at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
            at com.sun.mail.pop3.Protocol.<init>(Protocol.java:81)
            at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:201)
            at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:144)
            ... 3 more

  • 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

    Hi!
    I got this error message at runtime.
    After adding value to the Intialcontext by adding the following code snippet:
    Properties p = new Properties();
    p.put("java.naming.factory.initial",
    "com.sun.jndi.cosnaming.CNCtxFactory");
    p.put("java.naming.provider.url",
    "iiop://127.0.0.1:9010");
    initContext = new javax.naming.InitialContext(p);
    After this i am getting different error message:
    org.omg.CORBA.COMM_FAILURE:
    minor code: 1 completed: Maybe at om.sun.corba.se.internal.iiop.IIOPConnection.purge_calls(Unknown Source)
    at com.sun.corba.se.internal.iiop.ReaderThread.run(Unknown Source)
    Looking forward a proper solution
    for this problem.
    Thanks in advance.
    Regards,
    James Arun

    I have find the code to specify the naming context property to access another host
    Properties props = new Properties();
    props.setProperty("java.naming.factory.initial",
    "com.sun.enterprise.naming.SerialInitContextFactory");
    props.setProperty("java.naming.factory.url.pkgs",
    "com.sun.enterprise.naming");
    props.setProperty("java.naming.factory.state",
    "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
    // optional. Defaults to localhost. Only needed if web server is running
    // on a different host than the appserver
    props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
    // optional. Defaults to 3700. Only needed if target orb port is not 3700.
    props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

  • How to get rid of  "javax.naming.NoInitialContextException"

    Hi,
    Iam learning ejb. I was practicing the stateless session bean. I wrote a sample hello world application. While executing the client am getting the following error.
    {color:#ff0000}Exception in thread "main" 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 hw.HelloClient.main(HelloClient.java:20){color}
    My Client program:
    {color:#ff0000}package hw;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.*;
    import java.util.*;
    public class HelloClient {
    public static void main(String[] args)throws Exception {
    Properties prop = System.getProperties();
    Context ctx= new InitialContext(prop); {color}{color:#ff0000}{color:#800000}// (Line no :20) here only error is pointing
    {color:#ff0000}Object obj = ctx.lookup("HelloHome");
    HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj,HelloHome.class);
    Hello hello = home.create();
    System.out.println(hello.hello());
    hello.remove();
    }{color}{color}
    {color}
    please suggest me a solution. what has gone wrong!!

    At a guess, I would say you "Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file". But I'm just guessing.

  • Javax.naming.NoInitialContextException: Cannot instantiate class:

    I have written a client for my statleless ejb bean.The bea is deployed on weblogic server.when i am trying to access the bean through client with code
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    env.put(Context.PROVIDER_URL, "t3://localhost:8001");
    InitialContext ic = new InitialContext(env);
    following Exception is being thrown at runtime
    E:\EJBTest>java example.Client
    Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi.WLInitial
    ContextFactory [Root exception is java.lang.ClassNotFoundException: weblogic.jndi.WLInitialContextFactory]
    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.init(Unknown Source)
    at javax.naming.InitialContext.<init>(Unknown Source)
    at example.Client.main(Client.java:23)
    Caused by: java.lang.ClassNotFoundException: weblogic.jndi.WLInitialContextFactory
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
    ... 5 more
    the Same program was woking fine earlier ..
    Unable to locate the problem

    Can anyone help on this ..
    Thanks in advance..

  • Naming error: javax.naming.NoInitialContextException

    I get the below error message when I try to run the testing class below that. I googled the exception and read:
    This exception is thrown when no initial context implementation can be created. The policy of how an initial context implementation is selected is described in the documentation of the InitialContext class.
    // then I read this: http://publib.boulder.ibm.com/infocenter/adiehelp/index.jsp?topic=/com.sun.api.doc/javax/naming/NoInitialContextException.html
    This exception can be thrown during any interaction with the InitialContext, not only when the InitialContext is constructed. For example, the implementation of the initial context might lazily retrieve the context only when actual methods are invoked on it.
    I really dont understand what I read. Could someone please explain what my issue is and why it is occurring and how I could fix it.
    Thank you in advance,
    Crystal
    Naming error: javax.naming.NoInitialContextException: Need to specify class name
    in environment or system property, or as an applet parameter, or in an applicat
    ion resource file:  java.naming.factory.initial
    Exception in thread "main" java.lang.NullPointerException
            at notifier.notifierMethod.SiteManager(notifierMethod.java:230)
            at notifier.testing.main(testing.java:22)
    testing.java
    class testing {
        public static void main(String[] args) {
            //Display "Hello World!"
            System.out.println("Hello World!");
            notifier notifierInformation = new notifier();
            //session.setAttribute("notifier", notifierInformation);
            //get db connection
            database.DataFactory dbf = database.DataFactory.getDataFactory(database.DataFactory.sybase);
            notifierInterface notifierDB = dbf.getNotifierInterface();
            notifier sitemanager = notifierDB.SiteManager(newID, notifierInformation);  // LINE 22
    notifierMethod
    public notifier SiteManager(String newID, notifier notifierInformation) {
            try {
                ArrayList sitemgrList = new ArrayList();
                this.conn = database.SybaseDAO.grabConnection();
                cs = conn.prepareCall("{call mt."+newID+"_Notifier_SiteManager()}"); // LINE 230
                rs = cs.executeQuery();
                while(rs.next()) {
                    String owner = rs.getString(1);
                        sitemgrList.add(owner);
                notifierInformation.setSitemgrList(sitemgrList);
    }

    Aleen - Thank you for your help but I just dont get what you are saying at all! I am reading through all the links and its just not clicking with me. Is it possible for you to show me a vague example of what you mean?
    What do you mean by system properties/enviroment parameters? Do you mean what is in my web.xml/server.xml, like so?
    public static Connection grabConnection() {
            Connection conn = null;
            try {
                Context ctx = (Context)new InitialContext().lookup("java:comp/env");
                DataSource ds = (DataSource)ctx.lookup("jdbc/connectDB");
                conn = ds.getConnection();
            } catch(SQLException e) { System.err.println("SQL error: " + e);
            } catch(NamingException n) { System.err.println("Naming error: " + n);
            return conn;
    web.xml
    <description>MySQL Test App</description>
    <resource-ref>
          <description>DB Connection</description>
          <res-ref-name>jdbc/connectDB</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
    </resource-ref>
    server.xml
    <Context path="/appName" docBase="/appName"
            debug="5" reloadable="true" crossContext="true">
      <Logger className="org.apache.catalina.logger.FileLogger"
                 prefix="localhost_DBPool_log" suffix=".log"
                 timestamp="true"/>
    <Resource name="jdbc/connectDB" auth="Container" type="javax.sql.DataSource"
                   maxActive="5" maxIdle="1" maxWait="10000" removeAbandoned="true"
                removeAbandonedTimeout="60" logAbandoned="true"
                   username="myName" password="myPass" driverClassName="sun.jdbc.odbc.JdbcOdbcDriver"
                   url="jdbc:odbc:webdev"/>
    </Context>I just dont understand why if I have this code in a servlet it works fine but when I try to put it in a java class it doesnt work. And I am sorry in advance, I am not trying to be a pain in the a55 to you.. and I will keep reading
    Thanks - Crystal

  • EJB ERR: Namingexception caught:javax.naming.NoInitialContextException

    Hi,
    I am trying to deploy a sample ejb on Jboss and trying to call it from a client.
    I am getting the following error.
    *********Before LookUP*********
    Namingexception caught:javax.naming.NoInitialContextException: Need to specify c
    lass name in environment or system property, or as an applet parameter, or in an
    application resource file: java.naming.factory.initial
    This is my client code for the ejb where I have specified the INITIAL_CONTEXT_FACTORY and PROVIDER_URL..
    Am I missing something here?
    Is there any other way to go about this. Any help would be greatly appreciated.
    Thanks and Regards,
    Ajith
    THE CLIENT CODE IS AS GIVEN BELOW
    package simple_bean_client;
    import javax.ejb.*;
    import simpleBean.*;
    import javax.naming.Context;
    import java.util.Properties;
    import java.util.Hashtable;
    import javax.naming.InitialContext;
    class SalaryClient
         public static void main(String args[])
              Hashtable env = new Hashtable();
              env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
              env.put(Context.PROVIDER_URL, "localhost:1099");
              env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
         /*Properties pro = System.getProperties();
         pro.put( "java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory" );
         pro.put( "java.naming.provider.url","localhost:1099" );*/
              try{
                   InitialContext ctx=new InitialContext();
                   System.out.println("*********Before LookUP*********");
                   Object objRef=ctx.lookup("SalaryHome");
                   System.out.println("*********After LookUP*********");
                   SalaryHome home=(SalaryHome)javax.rmi.PortableRemoteObject.narrow(
                   objRef,SalaryHome.class);
                   Salary bean=home.create();
                   System.out.println("monthly net salary:"+bean.calculateSalary(28000,2,500));
              }catch(javax.naming.NamingException ne){
                   System.out.println("Namingexception caught:"+ne);
              }catch(javax.ejb.CreateException ce){
                   System.out.println("Create exeption caught:"+ce);
              }catch(java.rmi.RemoteException re){
                   System.out.println("Remote Exception caught:"+re);               
         }//closing main
    }//closing the class

    Found this . . .
    The following works for JBOSS, jndi.properties -file:
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.provider.url=jnp://your.host.com:1099
    The client code is as follows:
    Properties prop = new Properties();
    InputStream is = this.getClass().getClassLoader().getResourceAsStream(jndi_property_file);
    prop.load(is);
    Context ctx = new InitialContext(prop);
    anEJBHome =(EJBHome)PortableRemoteObject.narrow(ctx.lookup(homeClass.getName()),homeClass);

  • Javax.naming.NoInitialContextException when invoking an EJB

    Hi,
    I've deployed a stateless session EJB in oc4j and invoking it thru a Java client. I'm using Eclipse. I've a jndi.properties in config folder of my application which is in the classpath of the client code.
    The jndi.properties has :
    java.naming.factory.initial=com.evermind.server.rmi.RMIInitialContextFactory
    java.naming.provider.url=ormi://<localhost>:12401/OC4JEJB
    java.naming.security.principal=oc4jadmin
    java.naming.security.credentials=oc4jadmin
    where OC4JEJB is the application name deployed in oc4j.
    This jndi.properties file is in the classpath.
    My client code is :
    Server server = null; //interface
    ServerHome testSessionBean; //implementation of methods in Server interface
    try {
    Context ctx = new InitialContext();
    Object objref = ctx.lookup("EJBServer"); //JNDI name
    Object obj = PortableRemoteObject.narrow(objref, ServerHome.class);
    testSessionBean = (ServerHome) PortableRemoteObject.narrow(objref,
                             ServerHome.class);
    server = testSessionBean.create();
    } catch (...) {  }
    When i set the properties and do a look up
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
              "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.SECURITY_PRINCIPAL, "oc4jadmin");//oc4jadmin
    env.put(Context.SECURITY_CREDENTIALS, "oc4jadmin");
    env.put(Context.PROVIDER_URL,
         "ormi://<localhost>:12401/OC4JEJB");           
    InitialContext ctx = new InitialContext(env);
    it works perfectly fine.
    But when i use the jndi.properties it gives the following exception.
    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 client.ORION_EJB_Util.getServer(ORION_EJB_Util.java:203)
         at client.ORION_EJB_Util.<init>(ORION_EJB_Util.java:90)
         at client.TestClient.main(TestClient.java:26)
    client.exception.EJBUtilException
         at client.ORION_EJB_Util.getServer(ORION_EJB_Util.java:248)
         at client.ORION_EJB_Util.<init>(ORION_EJB_Util.java:90)
         at client.TestClient.main(TestClient.java:26)
    Invoking the server
    Inside getServer method
    Obtained Initial Context javax.naming.InitialContext@422ede
    Exception null
    I've tried placing the jndi.properties in j2ee/home/applib too. Where shud i place this jndi.properties and invoke the EJB?
    Could anyone help resolve this issue?
    Thanks in advance,
    Sprightee

    Try add your jndi.properties to your CLASSPATH.
    See this doc for more details of RMI.
    http://download-east.oracle.com/docs/cd/B31017_01/web.1013/b28958/rmi.htm#i1084792

  • Error in EJB client program (javax.naming.NoInitialContextException)

    Hi folks ,
    I'm new to j2ee programming and using Netbeans 5.5 , i created a session bean program and deployed successfully in JOnAS application server but i'm not able to run the client program which invokes session bean (EJB module ).
    when i run client program i'm getting the following 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(NamingManager.java:645)
            at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
            at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
            at javax.naming.InitialContext.lookup(InitialContext.java:351)
            at SimpleSessionClient.Main.main(Main.java:33)
    BUILD SUCCESSFUL (total time: 21 seconds)
    but the same program runnig perfectly when i deploy in Java System Application Server(8.2(JSAS))
    I included j2ee.jar and appserv-rt jar in classpath of client program for JSAS i don't know what are the jar files (which does the same function as j2ee.ar,appserv-rt.jar ) which is to be included for JOnAS .
    i'm struggling with this for the past two weeks . please tell me the solution .
    Thanks in advance

    Thanks for the suggestion artntek.
    I located the jndi.properties file in the %J2EE_HOME%\lib\classes folder, and I copied it to the %J2EE_HOME%\bin directory, but nothing seems to have changed.
    does anyone know what value should be associated with Context.INITIAL_CONTEXT_FACTORY in the properties for the InitialContext object? More specifically, what value should be used for the reference install of the 1.3 j2ee release from sun?
    This error suggests to me that a class name must be specified for the initial naming context factory - but I don't know what to use.

  • Javax.naming.NoInitialContextException ERROR

    I get the following error:
    Naming exception Error while connecting to the database : 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
    I created a Java class which has a method which connects to the database using:
    InitialContext ctx = new InitialContext();
    javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("jdbc/TMBLDB01CoreDS");
    m_connection = ds.getConnection();
    It errored out on the second line with the above error. I am using JDeveloper 10.1.3.
    I got it to work with a JDBC connection but prefer to use JNDI with JDBC.
    I started the Oracle AS Containers for J2EE (OC4J) by double clicking start_oc4j.bat.
    What is missing to make this work?

    Yes by adding the following solved that issue.
      env.put(JboContext.DEPLOY_PLATFORM, JboContext.PLATFORM_LOCAL);Another thing is I have added BC4J Client as library to my project. When I run I am getting
    javax.naming.NamingException: oracle.jbo.server.InitialContextImpl [Root exception is java.lang.ClassNotFoundException: oracle.jbo.server.InitialContextImpl]
         at oracle.jbo.common.JboInitialContextFactory.getInitialContext(JboInitialContextFactory.java:65)
         at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
         at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
         at javax.naming.InitialContext.init(InitialContext.java:223)
         at javax.naming.InitialContext.<init>(InitialContext.java:197)Do I need any other libraries?
    Thanks

  • Javax.naming.NoInitialContextException - jndi.properties

    I created an Enterprise application and deployed an Ejb project to the JBoss server.When I try to connect to the JNDI like this:
    Object o = initialContext.lookup(JNDI_NAME); I get this exception:
    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
    I put the jndi.properties file both into the client app and the bean project, near the .java files.
    here is the jndi.properties file:
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.provider.url=http://localhost:1099
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    I'm really confused...
    thanks..

    xyzt wrote:
    I put the jndi.properties file both into the client app and the bean project, near the .java files.
    here is the jndi.properties file:
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.provider.url=http://localhost:1099
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    I think that goes in
    ${JBOSS_HOME}/server/default/deploy/jms/jms-ds.xml

  • Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/stream

    I am trying to develop a web service client for amazon webservice.but i am getting this error while running the app. Can anyone please help me. I have installed the JWSDP and but could not understand why i have to locate all the jar files in the classpath?Please help.
    ===== error=========================================
    C:\abr\classes>java -classpath c:\abr\test.jar;C:\abr\jaxrpc-api.jar;C:\abr\jaxrpc-impl.jar;C:\abr\jaxrpc-spi.jar;c:\abr\classes\amazon.jar;C:\abr\mail.jar;C:\a
    br\saaj-api.jar;C:\abr\activation.jar;c:\abr\FastInfoset.jar;%classpath% Client
    [b]Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/stream/XMLS
    treamWriter
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at com.sun.xml.rpc.client.StreamingSender._writeRequest(StreamingSender.
    java:672)
    at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:87)
    at amazon.AmazonSearchPort_Stub.authorSearchRequest(AmazonSearchPort_Stu
    b.java:988)
    at Client.main(Client.java:21)

    I'm assuming you're using JWSDP 1.6 as I see Fastinfoset.jar in your list. You are missing some jar files in your classpath there. The best way to know what you need is to look at the release notes for JWSDP 1.6. Since you're building a web serivce start with the table in there and lookup JAX-RPC. It'll show you what jar files are needed and what other libraries are needed. Now depending on what you're doing you don't really need all those.
    For sure you're missing jsr173_api.jar which is where I believe that class you need is located. This is in the JWSDP_1_6\sjsxp\lib directory. You will probably need the other jar thats in there too. Best bet is to follow the dependancy chart in the release notes.
    This should get you going.
    Ryan

Maybe you are looking for

  • Session Timeout when purchasing

    When I try to purchase a song, iTunes asks me to approve the new Terms & Conditions. When I do, it says "Session Timeout, please try this operation again from the beginning". What's going on?

  • RFC function module - to have it as time dependent

    Hi, I have a RFC call to CRM system from R/3 side.  This call is made to get email address of users in CRM system - during the triggering of order confirmation output.  Some times the RFC queue is full and these calls also get in to the queue blockin

  • Limited drop down list in selection criteria in Crystal Report

    I have designed a Crystal Report to produce Item Labels using Crystal Reports for SAP Business One. The design has a Dynamic parameter for the selection of Item Code, linked to the OITM table in the database The customer database has 5000+ items. Whe

  • Pending calls, problem with distinguishing which call that was disconnect

    Hi everybody, I have an application that gets triggered by incoming calls. When the calls are rejected a menu will show up. When users have pending calls however the menu should only be triggered when the newly arrived call is disconnected not if the

  • What if my itunes library is too big

    if i have an Itunes library that is 100 GB, what happens if i have a 16 GB IPad?