Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem finding InitialContext

 
Vishva Rajput
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a stand alone Java Application running on WSAD 5.1. How do i get the initialcontext???

I am using the code

Hashtable props = new Hashtable ();
props.put (Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
props.put(Context.PROVIDER_URL,"iiop://localhost:2809");
Context ctx = new InitialContext(props);



It gives the following error.

javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory. Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:374)
at java.lang.ClassLoader.loadClass(ClassLoader.java:562)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:438)
at java.lang.ClassLoader.loadClass(ClassLoader.java:494)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:256)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:59)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:661)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:256)
at javax.naming.InitialContext.init(InitialContext.java:232)
at javax.naming.InitialContext.<init>(InitialContext.java:208)
at test.LocalTest.mail(LocalTest.java:46)
at test.LocalTest.main(LocalTest.java:35)


Please help.

Regards, Vishva
 
Vishy Raman
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is this java application file located? Try placing the file in EJB project and J2EE project. If the file is in Java client project - it wouldn't find the EJB context.

There could be some other ways to create the EJBContext - if you want to test it real quick, the above ways should work
 
Andre Mermegas
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well thats a pretty obvious exception, you don't have the naming.jar in your classpath, you probably will need other dependencies as well from the websphere app\lib directory.
 
Vishva Rajput
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishi / Andre,

Thanks!
It works fine the way you suggested. How come? Also I need to run it as a standalone application, JUnit, what do i need to do. Add naming.jar, and what else.

Vishva
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic