• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NoInitialContextException EJB Client (Java main class)

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using a Java main class as a client to test a simple stateless session EJB that will spit out hello world.

I get exception below where I try to look up for home interface:

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:674)
at com.labcorp.messaging.MyTest.main(MyTest.java:34)

I get exception below in line:
home = (SessHome)ic.lookup("java:comp/env/ejb/com/myComp/messaging/SessHome");

com.myComp.messaging.SessHome is my Home interface.


public class MyTest {

public static void main(String[] args) {
InitialContext ic = null;
try {
ic = new InitialContext();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

SessHome home = null;
try {
home = (SessHome)ic.lookup("java:comp/env/ejb/com/labcorp/messaging/SessHome");
} catch (NamingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}


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:674)
at com.labcorp.messaging.MyTest.main(MyTest.java:34)
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In most cases, when doing a standalone client, you'll need to use a non-default constructor of InitialContext so it knows what to do. Usually, when you do a simple "new InitialContext()" there's some file somewhere that the class will use to actually create the right objects for you. But in a standalone client, that's not the case, right?

Check out your JNDI server docs to find out what properties to put in the Map you pass to the InitialContext constructor.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there!
i also got the same problem when i tried to access
jndi names of the JBOSS server. Finally how could i solved this is, simply changed the main program into a servlet and run. I think mostly it will work. I hope u r familiar with servlets jsps.
Regards.
Mahen
 
Something must be done about this. Let's start by reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic