Search code examples
javadatabasejmxwebsphere-liberty

How do i create a data source in WebSphere Liberty via JMX


I am unable to find a code snippet for creating a datasource in Liberty via a Java Client. I looked up the ConnectionManagerMbean, but its documentation says that the Mbean instance wont be available until it is first used.

Can someone point me in right direction. I am kinda new to both Liberty and JMX so please bear with me if this sounds kinda rookyish.

Thanks in advance.


Solution

  • The reason you are unable to locate any examples of creating a Liberty data source via JMX is because it is not possible in Liberty to create data sources via JMX. In Liberty, data sources can be created via server configuration - the dataSource element - or via the @DataSourceDefinition annotation within an application component or <data-source> element within a deployment descriptor (such as web.xml) of an application.

    Once you have created the data source, as you mentioned from the ConnectionManagerMBean documentation, you will need to use the data source first (access it from an application) before the MBean is made available. This aligns with Liberty's goals of having fast startup time and only loading/initializing what applications actually use. The behavior you observe sounds consistent with this, and you just need to perform an operation within your application first, and then you should hopefully be able to access the MBean.