Datasource is configured in server.xml file. How can I load the datasource from this file in a stand alone java application?
If i try with
Context initialContext = new InitialContext();
DataSource dataSource = (DataSource) csDBEnvContext.lookup(DATASOURCE_NAME);
i get the following exception
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
Same code when called from jsp gets executed fine. To my understanding, in this case container plays the key role in proper execution.
Datasource name alone is shared to me. username, password are not shared since it is production environment.
You should never be executing code like that from a JSP, I know it will work but it is very bad code smell. Data access stuff does not belong in the view layer.
You say standalone application. To be this means you are not running inside of a container. If this is the case you are not going to be able to look up the datasource using JNDI. Rather you are going to have to establish your own connection.