Search code examples
javawebsphere

Requirement to run standalone client for WAS 7


What all Jars required to run standalone Java client while making database connection to Websphere v7.0

Code

Hashtable parms = new Hashtable();
parms.put(Context.INITIAL_CONTEXT_FACTORY, Database.DB_CONTEXT_FACTORY);
parms.put(Context.PROVIDER_URL, Database.DB_PROVIDER_URL);
logger.debug("Using context of database with parameter "+parms);
context = new InitialContext(parms);
dataSource = (DataSource) context.lookup(getName());
logger.debug("Using context of database with and the context is "+dataSource);
Connection conn = dataSource.getConnection();

Error

ERROR com.ibm.nzna.shared.util.LogSystem  - javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory [Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:685)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:318)
at javax.naming.InitialContext.init(InitialContext.java:253)
at javax.naming.InitialContext.<init>(InitialContext.java:227)
at com.ibm.nzna.shared.db.Database.connect(Database.java:140)
at com.ibm.nzna.shared.db.DatabaseSystem.createConnection(DatabaseSystem.java:243)
at com.ibm.nzna.projects.qit.app.PCDInitializeThread.run(PCDInitializeThread.java:180)
at java.lang.Thread.run(Thread.java:780)
Caused by: java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory
at java.lang.Class.forName(Class.java:176)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:75)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:682)
    ... 7 more

Solution

  • It seems you are missing WAS 7 client files in classpath. Get them from your WAS installation and add it to classpath. You may find those jars in installation ---> runtime folder.