• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JNDI lookup....need help

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My problem is that i cant get the DataSource object in my java program and the following error is thrown.
---------------------------------------------------
java.lang.NoClassDefFoundError: com/ibm/ejs/ras/TraceElement
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:212)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:656)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.(InitialContext.java:199)
at DataSourceCheck.main(DataSourceCheck.java:27)
Exception in thread "main"
--------------------------------------------------
Here is my Java program :
import java.sql.*;
import javax.naming.*;
import java.util.*;
class DataSourceCheck
{
public static void main(String[] args)
{
javax.sql.DataSource myDataSource= null;
try
{
String initialContextFactory = "com.ibm.websphere.naming.WsnInitialContextFactory";
String providerURL = "iiop://localhost:8081";
java.util.Properties props = new java.util.Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
props.put(Context.PROVIDER_URL, providerURL);
Context myContext = new InitialContext(props);
Connection myConnection = myDataSource.getConnection();
}
catch (Exception e)
{
e.printStackTrace();
System.out.println();
}
}
}

-------------------------------------------------
I start a Server instance from IBM WSAD and it runs on 8081.
Please suggest what to do .
 
Pappu Kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there is a typo in the code....
here it is again....
i fail to get the context itself....
_____________________________________________
import java.sql.*;
import javax.naming.*;
import java.util.*;
class DataSourceCheck
{

public static void main(String[] args)
{
javax.sql.DataSource myDataSource= null;
try
{

String initialContextFactory = "com.ibm.websphere.naming.WsnInitialContextFactory";
String providerURL = "iiop://localhost:900";
java.util.Properties props = new java.util.Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
props.put(Context.PROVIDER_URL, providerURL);
Context myContext = new InitialContext(props);

//myDataSource = (javax.sql.DataSource)myContext.lookup("jdbc/oracle/OracleDataSource");
//Connection myConnection = myDataSource.getConnection();
}
catch (Exception e)
{
e.printStackTrace();
System.out.println();
}
}
}
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me guess, you're not trying to start this by packaging it as a client JAR file and then putting that inside your EAR file and using launchClient, right? Unfortunately, that is the ONLY way to run Java clients against WebSphere. Do a search for "launchClient" in the InfoCenter for details.
Kyle
 
Pappu Kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will try the launchclient stuff you just mentioned. Here is another thing i wanna ask you....what should i do to make this work if i :
start a websphere instance from inside the WSAD. And try to get the DataSource object from simple program written outside the WSAD IDE..say in C:\DataSourceCheck.java
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The WSAD instance will work fine, but the Java client will not work, period, end of story. The ONLY way to get a Java client to look something up from a WebSphere JNDI is through the startup method that I told you.
Kyle
[ March 16, 2003: Message edited by: Kyle Brown ]
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rahul,
I've faced the same problem and this is how I’ve resolved it. Check in you WAS's lib there you will find ras.jar put that in your class path and see.
What I have done is first of all place my java class in the lib and set all the jars to it
These are the most important jars to be in your set classpath=.\j2ee.jar;.\naming.jar;.\ecutils.jar;..\properties;.
Just try out this way and let me know
For me it’s worked. Yet I didn’t find out a way to do it from remote machine...
Hope this would help.
Regards
Siva
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sivalingam Sivasuthan:
Hi Rahul,
I've faced the same problem and this is how I’ve resolved it. Check in you WAS's lib there you will find ras.jar put that in your class path and see.
What I have done is first of all place my java class in the lib and set all the jars to it
These are the most important jars to be in your set classpath=.\j2ee.jar;.\naming.jar;.\ecutils.jar;..\properties;.
Just try out this way and let me know
For me it’s worked. Yet I didn’t find out a way to do it from remote machine...
Hope this would help.
Regards
Siva


Siva, read the section in the InfoCenter on Application Clients. You MUST install an application client container from the WebShere CD on the remote machine and then use one of the three options indicated in the InfoCenter.
Kyle
 
Sivalingam Sivasuthan
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kyle,
You are right According to the InfoCenter it clearly says I have to install an application client container. But It doesn�t mean that we cant do it without that. Here are the Steps if you wish try this its works fine with WAS5.0.
1.Copy the jre folder from the WAS_HOME\java\ and paste it in your client Machine and set the Path that jre\bin. Make sure that that is the path for the java.exe
2.copy the following jar files from WAS_HOME\lib
�ecutils.jar
�ffdc.jar
�idl.jar
�iwsorb.jar
�j2ee.jar
�naming.jar
�namingclient.jar
�namingserver.jar
�ras.jar
�tx.jar
�txPrivate.jar
�utils.jar
�wsexception.jar
and place it in your classpath
3.copy implfactory.properties file from WAS_HOME\ properties and place it in your classpath
4.and what ever the EJBs jar file you can copy this from your WAS_HOME\installedApps\<servername>\<AppName.ear> and place it in your classpath
5.Now write you Client and run it will run Sample Client Code:
<CODE>
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.*;
import javax.ejb.*;
import javax.rmi.*;
import com.jkcs.ws.demo.ejb.entity.*;
public class MyClient{
public static void main(String args[]){
UsersRemote usersLocal = null;
UsersRemoteHome usersHome = null;
String LoginStatus = null;
System.out.println("Begining of the userLogin method...");
try{
if (usersHome == null){
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL, "iiop://bdc-server1:2809");
Context initialContext = new InitialContext(env);
Object objRef = initialContext.lookup("Users");
usersHome = (UsersRemoteHome) PortableRemoteObject.narrow (objRef,UsersRemoteHome.class);
System.out.println("Successfully Got the UserHome");
}
usersLocal = usersHome.findByIdentity("Siva", "password");
LoginStatus = "Hi "+ usersLocal.getUsername()
+ "! you are Successfully Logged in";
} catch (NamingException ne) {
System.out.println("NameingException.....");
ne.printStackTrace();
} catch (FinderException fe) {
System.out.println("FinderException...");
LoginStatus = "Login Failed!, Please try Again.";
fe.printStackTrace();
} catch (Exception fe) {
System.out.println("Exception...");
LoginStatus = "Login Failed!, Please try Again.";
fe.printStackTrace();
}

}
}
</code>

Regards
Siva
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic