aspose file tools*
The moose likes Websphere and the fly likes JNDI lookup....need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "JNDI lookup....need help" Watch "JNDI lookup....need help" New topic
Author

JNDI lookup....need help

Pappu Kumar
Ranch Hand

Joined: Oct 01, 2002
Posts: 69
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

Joined: Oct 01, 2002
Posts: 69
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();
}
}
}
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
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


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Pappu Kumar
Ranch Hand

Joined: Oct 01, 2002
Posts: 69
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
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
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 ]
Sivalingam Sivasuthan
Ranch Hand

Joined: Jan 12, 2001
Posts: 75
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<br /> Sun Certified Programmer for the Java™2 Platform
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
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

Joined: Jan 12, 2001
Posts: 75
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNDI lookup....need help