This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Share information between Web App and Stand-alone Java App Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "Share information between Web App and Stand-alone Java App" Watch "Share information between Web App and Stand-alone Java App" New topic

Share information between Web App and Stand-alone Java App

David Wei

Joined: Jan 04, 2002
Posts: 17
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

Joined: Jan 30, 2002
Posts: 3451
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.

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
I agree. Here's the link:
subject: Share information between Web App and Stand-alone Java App
It's not a secret anymore!