Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Share information between Web App and Stand-alone Java App  RSS feed

David Wei
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Merry Christmas!
I am writing a stand-alone java application to send out emails to the people whose subscribed item status is changed through a web application. I need to share some property information, like datasource name (dsn) and user information. In my web application using WAS 4.0, I created datasource and Ldap directory and tried to use jndi to obtain the shared information.
When I run my main method to get database connection by using jndi name for database name, my code is like this
public DataSource getDataSource()
throws NamingException
InitialContextctx=new InitialContext();
return(DataSource) ctx.lookup(dataSourceName);

I got the exception "Caught exception when resolving initial reference=NameService" in the first line of this method

Can you help me on this?
Thanks in advance!
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David and welcome to JavaRanch. It's a coincidence that we have been struggling with a similar problem at work for the last couple of days though we are using WAS 5.0 and are getting a Malformed URL from the InitialContext (it doesn't seem to recognize the corbaloc protocol). A work around is to use pure CORBA.
Get an ORB in your main and initialize to the WebSphere ORB:

Get the NameService:

Get the DataSource:

You will obviously need to make some adjustments to this code to match your host, ORB port etc. I am still investigating why we are having trouble using InitialContext and if I find the answer, I'll post it back here.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!