My question relates to configuring database connectivity in the Liberty profile when on Bluemix
I would like to configure my server.xml as per https://www-01.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/twlp_dep_configuring_ds.html in order to connect to a DashDb instance, which is bound to my app
According to this documentation states DashDb is a service that supports automatic configuration https://www.ng.bluemix.net/docs/starters/liberty/index.html#automaticconfigurationofboundservices Which means I can use references to cloud variables in my "datasource" element
My specific question relates to what location can be specified for the "library" element referenced by the datasource?
The sample given in the Bluemix documentation shows how to connect to DashDb by using DriverManager and using the connection details in the VCAP_SERVICES https://www.ng.bluemix.net/docs/services/dashDB/index.html#connect
This suggests that the DashDb driver is on the classpath, in a location accessible to the application where the code runs.
What location is this and can it be referenced in the server.xml in library element, so that I can use a DataSource resource to connect to my DashDb instance.
Thanks in advance
Answer by Ram Vennam (2913) | Aug 06, 2015 at 12:58 PM
When you bind a dashdb service to a Liberty application, the server.xml is automatically configured with dataSource with a jndi name. The database driver jars are also added.
cf files MyAppName app/wlp/usr/servers/defaultServer/server.xml
<dataSource id='db2-dashDB-a1' jdbcDriverRef='db2-driver' jndiName='jdbc/dashDB-a1' statementCacheSize='30' transactional='true'>
...
</dataSource>
<jdbcDriver id='db2-driver' libraryRef='db2-library'/>
<library id='db2-library'>
<fileset id='db2-fileset' dir='${server.config.dir}/lib' includes='db2jcc4.jar db2jcc_license_cu.jar'/>
</library>
The database driver jars are here:
cf files MyAppName app/wlp/usr/servers/defaultServer/lib
db2jcc4.jar 3.7M
db2jcc_license_cu.jar 1015B
Hope this answers your question.
Thanks Ram. Much appreciated. I have a follow up.
I am reading the "Opting out of service auto-configuration" part of https://www.ng.bluemix.net/docs/starters/liberty/index.html#automaticconfigurationofboundservices
It states "I am providing a server.xml file and I have provided the configuration stanzas for theSQLDB instance because I require a non-standard datasource configuration. I do not want the Liberty buildpack to update my server.xml file, but I still require the Liberty buildpack to ensure that the appropriate supporting software is installed."
I would like to achieve something similar.
Judging from the example you cite below, the Bluemix deployment process copies those JARS to ${server.config.dir}/lib
Is there a way that I can configure the service auto configuration to leave the server.xml as is , but that still copies those JARS to ${server.config.dir}/lib ?
Thanks in advance
Closing this question. Found that what I needed to do was to specify the option of opting out of the config only , as per https://www.ng.bluemix.net/docs/starters/liberty/index.html#automaticconfigurationofboundservices
Hi Ram,
I suppose that the jndi name for dashDb auto-config (jndiName='jdbc/dashDB-a1') is standard and can therefore be used in a JPA persistence.xml config file.
Is that correct?
It appears the JNDI reference is named after the service that's bound to your application. So if you bound a dashDB instance named "MyAmazingDB", you'd get "jdbc/MyAmazingDB".
Answer by Shepherd123456 (1) | Jun 21, 2017 at 01:52 AM
Hi Ram,
In my case I have the Dash DB and Liberty in separate spaces, I cannot connect them directly. I have tried packaging the Liberty server along with the war. But after it gets pushed successfully, I cannot figure out the endpoint of my servlet. I have just changed the hostname with the new one. Could you please guide me, whats the issue, or should i do it in any other way.
@Resource annotation not working with Analytics Warehouse connection 5 Answers
Migration from Jetty Google App Engine to Liberty Bluemix 2 Answers
ibmliberty container crashing locally 3 Answers
Packaging a war into a Liberty server 2 Answers
why is FileNotFoundException coming in liberty server when file exists in war file 2 Answers