my dog learned polymorphism*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Subi,

Try to add the weblogic.jar to the client�s classpath like this:

Here the $BEA_HOME is the path to bea folder (usually C:\bea on Windows). Let me know if it works.
Regards.


I think, therefore I exist -- Rene Descartes
subi phoenix
Greenhorn

Joined: Jul 13, 2005
Posts: 15
Thank you Valentin,

I tried but i got this different exception:

C:\bea\user_projects\domains\mydomain\myEJB>java Client
Before lookup
Got Initial Context
Called From Client Catch
javax.naming.NameNotFoundException: Unable to resolve 'StatelessSessionHome' Resolved ; remaining name 'State
lessSessionHome'
at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:284)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:244)
at weblogic.jndi.internal.ServerNamingNode_811_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:338)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:333)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at Client.main(Client.java:18)
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'StatelessSessionHome' Resolved
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:869)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:230)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:166)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:188)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:466)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:409)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:353)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:144)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:404)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)


But all my classes are in the same directory.

Pls help me out.
subi phoenix
Greenhorn

Joined: Jul 13, 2005
Posts: 15
Before executing this i have set my path & classpath;


C:\bea\user_projects\domains\mydomain>set path=%path%;c:\j2sdk1.4\bin;.;

C:\bea\user_projects\domains\mydomain>set classpath=%classpath%;.;C:\bea\weblogic81\server\bin\weblogic.jar

Pls help
Frank Ertl
Ranch Hand

Joined: Apr 25, 2005
Posts: 59
If I compare your classpath settings and the path where you start the client I see that there are differences:

C:\bea\user_projects\domains\mydomain\myEJB


vs.

C:\bea\user_projects\domains\mydomain


Perhaps it's a typo, but try to verify this...
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Subi,

It looks like the lookup fails because the client cannot locate the bean. You must check your deployment descriptors and check the jndi-name of your bean. If you�re using ejb references, I would suggest you to do the lookup into the Environment Naming Context (ENC) like this:

By the way, since this is a remote client you better use the CORBA-like narrowing approach rather than casting. See some examples on the net, they are plenty.
Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NoInitialContextException
 
Similar Threads
What might be the problem??
NoInitialContextException
How to do connection pooling for cmp?
Getting Error while runnning Session Bean Client
Please help me in the cmp problem