This week's book giveaway is in the Testing forum.
We're giving away four copies of Practical Unit Testing with TestNG and Mockito and have Tomek Kaczanowski on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes IBM WSAD...error Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Reply Bookmark "IBM WSAD...error" Watch "IBM WSAD...error" New topic
Author

IBM WSAD...error

Pappu Kumar
Ranch Hand

Joined: Oct 01, 2002
Posts: 69
Hi guys , i had posted a DataSource question before...but i was able to figure that out. My new 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.<init>(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 .
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3878
OK, the issue here is that when you just run a Java program in WSAD you're not starting it within WebSphere's J2EE client container. This is a common question we address in the WebSphere forum every day or so.
Inside WSAD, the way you address this is to make sure you do two things:
(1) Your client program must be within an Application Client Project associated with an EAR Project.
(2) To Run your client, first start the server. Then select your client program class (the one with the main() method) inside the J2EE perspective. Open the Run menu at the top of the screen and select "Run..." (Make sure you select Run... and not Run As).
(3) In the launch Configurations panel, select "WebSphere 5 Application Client" and press the "New" Button. Give your configuration a name (other than "new configuration" -- I usually use the same name as the client program class). If there are program arguments,enter them in the arguments tab. Hit "Apply" and the new configuration will be added.
(4) To run the client, press the "Run" button on ths page.
Note this will ONLY work if you are in WSAD 5.0. If you are in WSAD 4.0, you need to follow the instructions in this article.
Kyle
[ March 18, 2003: Message edited by: Kyle Brown ]

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.
 
 
subject: IBM WSAD...error
 
Threads others viewed
Cannot Access Ejb from Java Applcation
WAS 6.1 JMX AdminClient.
problem in context lookup
Java mail using gmail
JNDI lookup....need help
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture