aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes NoInitialContextException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "NoInitialContextException" Watch "NoInitialContextException" New topic
Author

NoInitialContextException

subi phoenix
Greenhorn

Joined: Jul 13, 2005
Posts: 15
Hi,

I deployed a stateless session bean in weblogic 8.1
successfully. But when I run client program from command prompt i got the following exception.

C:\bea\user_projects\domains\mydomain\myEJB>java Client
Before lookup
Called From Client Catch
javax.naming.NoInitialContextException: Cannot
instantiate class: weblogic.jndi.WLInitialContextFactory [Root exception is java.lang.ClassNotFoundException: web
logic.jndi.WLInitialContextFactory]

at javax.naming.spi.NamingManager.getInitialContext(Unknown
Source)
at Javax.naming.InitialContext.getDefaultInitCtx(UnknownSource)
at javax.naming.InitialContext.init(UnknownSource)
at javax.naming.InitialContext.<init>(Unknown Source)
at Client.main(Client.java:16)

Caused by: java.lang.ClassNotFoundException:
weblogic.jndi.WLInitialContextFactory
at java.net.URLClassLoader$1.run(UnknownSource)
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



Source Code:


Home Interface:

import javax.ejb.*;
import java.rmi.*;

public interface StatelessSessionHome extends EJBHome
{
public StatelessSession create() throws RemoteException,CreateException;
}






Remote Interface:

import javax.ejb.*;
import java.rmi.*;

public interface StatelessSession extends EJBObject
{
public String getName() throws RemoteException;
public void setName(String stName) throws RemoteException;
}



EJB Class:
import javax.ejb.*;
import javax.naming.*;

public class StatelessSessionEJB implements SessionBean
{
private SessionContext ctx;
private String strName;
public void ejbActivate(){
System.out.println("ejbActivate ("+strName+")called.");
}

public void ejbRemove()
{
System.out.println("ejbRemove("+strName+")Called.");
}

public void ejbPassivate()
{
System.out.println("ejbPassivate("+strName+")called.");
}

public void setSessionContext(SessionContext ctx)
{
System.out.println("setSessionContext()called.");
this.ctx = ctx;
}

public void ejbCreate() throws CreateException
{
System.out.println("ejbCreate() called");
}
public void setName(String value)
{
strName = value;
System.out.println("setName("+strName+")called.");
}
public String getName()
{
System.out.println("getName("+strName+")called.");
return strName;
}
}


Client.java

import javax.naming.*;
import javax.rmi.*;
import java.rmi.*;
import java.util.*;

public class Client
{
public static void main(String args[])
{
try
{
System.out.println("Before lookup");
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
prop.put(Context.PROVIDER_URL,"t3://localhost:7001" );
InitialContext ctx = new InitialContext(prop);
System.out.println("Got Initial Context");
StatelessSessionHome home = (StatelessSessionHome)ctx.lookup("StatelessSessionHome");
StatelessSession rem = home.create();
System.out.println("create called");
System.out.println("Getting name from Bean");
String name = rem.getName();
System.out.println("Name : "+name);
System.out.println("Setting name to Bean");
rem.setName(args[0]);
Thread.sleep(1000);
name = rem.getName();
System.out.println("Name : "+name);
}

catch(Exception er)
{
System.out.println("Called From Client Catch");
er.printStackTrace();
}
}
}


On the command prompt (server) prompt I got these:
setSessionContext()called.
ejbCreate() called
setSessionContext()called.
ejbCreate() called
setSessionContext()called.
ejbCreate() called
setSessionContext()called.
ejbCreate() called
setSessionContext()called.
ejbCreate() called

seems somewhere problem in creating the initial context.

Could you enlighten me where is wrong?Please..


Thank you,<br />Subi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NoInitialContextException
 
Similar Threads
Getting Error while runnning Session Bean Client
What might be the problem??
NoInitialContextException
Please help me in the cmp problem
How to do connection pooling for cmp?