aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Initial Context Factory error with JBoss 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 "Initial Context Factory error with JBoss" Watch "Initial Context Factory error with JBoss" New topic
Author

Initial Context Factory error with JBoss

Craig Gaffney
Greenhorn

Joined: Mar 30, 2004
Posts: 15
G'Day all,
I am trying to do a simple JBoss EJB (Hello World), and access it via a java client. It's based of an example in Java2 Unleashed, which uses WebLogic (I don't have on my network). Both client and server are on the same machine (currently), but I am getting some problems.

I get the following error message

Cannot instantiate class: org.jboss.naming.HttpNamingContextFactory
javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming.HttpNamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.HttpNamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at com.rags.ejb.simple.SimpleEJBClient.main(SimpleEJBClient.java:29)
Caused by: java.lang.ClassNotFoundException: org.jboss.naming.HttpNamingContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
... 4 more


Now, I this is the code in the client that is failing

Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");
h.put(Context.PROVIDER_URL, "https://localhost:8443/invoker/JNDIFactory");

//lookup jndi initial context
Context initial = new InitialContext(h);
Context ctx = (Context)initial.lookup("java:comp/env");

It seems like I am using the wrong context values, but I cannot find out what I should have there. Can anyone point me in the right direction?


BTW, I am using JBoss 3.2.5 on Mandrake 10.0, J2SDK 1.4.2_05. I think that's all for the environment....

Thanks in advance for your help,

Craig.
alen agmon
Greenhorn

Joined: Sep 22, 2004
Posts: 11
there are few things that can be wrong here:
first-
are u writing an "application client" or a test class?
one way to solve it , if u write a test class is to include in your compilation's classpath a jndi.prperties file contains the naming stuff ,

like:

java.naming.factory.initial = org.jnp.interfaces.NamingcontextFactory
java.naming.factory.url.pkgs= org.jboss.naming rg.jnp.interfaces
java.naming.provider.url=localhost

include that as jndi.properties in your classpath and throw all those Properties.put stuff from your code.

second-
about the context in the code the correct way is :
(this is how you call it from a servlet for example)

context ctx = new InitialContext();
Object ref = ctx.lookup("java:comp/env/ejb/yourEjbHome");
EjbHome home = (EjbHome)PortableRemoteObject.narrow(ref,EjbHome.class);
Ejb ejb = home.create();
Craig Gaffney
Greenhorn

Joined: Mar 30, 2004
Posts: 15
G'Day Alen,
I am writing an application client, not a test class.

The code is exactly as taken from the example from the Java2 Unleashed book, so if it isn't correct, it's their fault not mine.

As a possibility, could I have missed out a class file or jar file that should have been included in the client application? I wouldn't be surprised if that happened.

Anyway, thanks for the help so far.

Cheers,
Craig.
alen agmon
Greenhorn

Joined: Sep 22, 2004
Posts: 11
check out :

http://www.jboss.org/wiki/Wiki.jsp?page=WSClientAppl
alen agmon
Greenhorn

Joined: Sep 22, 2004
Posts: 11
and this example :

http://sourceforge.net/tracker/download.php?group_id=22866&atid=381174&file_id=67226&aid=840598

and another one from source forge:

http://sourceforge.net/tracker/index.php?func=detail&aid=840598&group_id=22866&atid=381174
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Initial Context Factory error with JBoss