• Post Reply Bookmark Topic Watch Topic
  • New Topic

NoInitialContextException EJB Client (Java main class)  RSS feed

 
Sam Gehouse
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • 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)
 
Mudi Appu
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your main class doesn�t know where server runs. Please keep your main classed informed that too.
Use following constructor to create ic
InitialContext(properties)

Here is a sample private method witch used to create InitialContext object with server information. (This method written for a WebLogic server runs on local host)

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!