This discussion is archived
1 2 Previous Next 19 Replies Latest reply: Mar 25, 2008 12:18 PM by 807581 Go to original post RSS
  • 15. Re: javax.naming.NoInitialContextException
    807581 Newbie
    Currently Being Moderated
    Hi javaBoy555,

    I am having the same exception as you did. How do you get it to run?

    Thanks,
    lesmantec
  • 16. Re: javax.naming.NoInitialContextException
    807581 Newbie
    Currently Being Moderated
    i am also facing the same exception while deploying the ejb 3.0 on jboss 4.0.4. I was trying to deploy the sample example from mastering ejb 3.0

    Thanx

    Edited by: kvsingh on Sep 22, 2007 8:30 AM
  • 17. Re: javax.naming.NoInitialContextException
    807581 Newbie
    Currently Being Moderated
    Got the solution for this.

    We have to add a IIOP Lisetener in the Admin console and mention the server ip.

    My simple code works in a LAN Environment.

         
    Properties props = new Properties();
              props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
              try {
                   Context ctx = new InitialContext(props);
                   
                   Object obj = ctx.lookup("corbaname:iiop:serverip:3700#InventoryBean");
                   System.out.println(obj);
              } catch (NamingException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              }
    This works fine.
  • 18. Re: javax.naming.NoInitialContextException
    807581 Newbie
    Currently Being Moderated
    I forgot onepoint.

    In the client machine we will have to start one service provided by Sun.

    orbd.exe which is there in jdk bin folder.

    Happy Development!!
  • 19. Re: 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
    807581 Newbie
    Currently Being Moderated
    Okay this problem is very close to mine, but for EJB 3.0. I have create a JUnit test to which attempts to communicate with a Remote object. Because I am outside the container of the app server I accomplish the following:
    public class JtdiSiteFinderTest {
         
         //String JNDI_NAME_SITE_FINDER ="java:comp/env/ejb/JtdiSiteFinder";
         String JNDI_NAME_SITE_FINDER ="java:comp/env/ejb/JtdiSiteFinder#jtdi.cm.ejb.bean.session.finder.JtdiSiteFinderRemote";
        private JtdiSiteFinderRemote jtdiSiteFinder = null;
        
        
        
         
         @Before
         public void prepareFinder(){
              try{
               Properties p = new Properties();
               p.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
               p.put("java.naming.provider.url", "corbaloc:iiop:1.2@127.0.0.1:3700");
               
               InitialContext ctx = new InitialContext();
               //jtdiSiteFinder =    (JtdiSiteFinderRemote)ctx.lookup(JtdiSiteFinderRemote.class.getName());
              jtdiSiteFinder = (JtdiSiteFinderRemote) ctx.lookup(JNDI_NAME_SITE_FINDER);           
              }catch(Exception e){
                   e.printStackTrace();
              }     
         }//end method 
         
         
         
         
         @After
         public void cleanupFinder(){
              
         }//end method 
         
         
         @Test
         public void findJtdiSiteBySiteId(){
              JtdiSite jtdiSite = null;
              
              jtdiSite = jtdiSiteFinder.findJtdiSiteBySiteID(9L, 1L);
              
              assertEquals(4, jtdiSite.getSiteId().intValue());
         }//end method 
    
    }
    I have tried with the properties fileand without. I am getting the following error when I attempt to connect using no properties I ge 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:288)
         at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
         at javax.naming.InitialContext.lookup(InitialContext.java:392)
         at jtdi.cm.ejb.session.finder.test.JtdiSiteFinderTest.prepareFinder(JtdiSiteFinderTest.java:37)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
         at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
         at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
         at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
         at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
         at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
         at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
         at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
         at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
         at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
         at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    All I am trying to accomplish is connect to a EJB 3.0 bean and call one method from a JUnit client. I have googled most of this information and have created the above method.

    Russ
1 2 Previous Next