Can we write standalone programs which use JNDI? I googled and it seems that JNDI can be used in conjunction with web-container i.e. to use JNDI, the JNDI support should come from a web-container?
Can we write a simple standalone program (with main() method) and uses JNDI to obtain the database connection? I searched a lot in google, however not sure if we can do this.
Any inputs highly appreciated.
Thanks
The problem JNDI solves is to be able to retrieve an object present in the JVM but inaccessible to your code, and do so at runtime using a string key.
You just need an implementation of this technology in your stand alone applications to use it. I did it with https://code.google.com/p/osjava/wiki/SimpleJNDI many moons ago.
However, JNDI is hardly mentioned these days because it has evolved into Dependency Injection (CDI in Java EE) where the lookup mechanism is moved outside your own code. If you are writing a new stand alone application I would suggest you look into Dagger 2 instead of JNDI. Notice that the project has quite a steep learning curve - you may want to experiment with https://github.com/ravn/dagger2-hello-world while learning it.