WebSphere Liberty is an application server offering by IBM. It is fast, dynamic, and easy for configuration. The server is built on the open-source Open Liberty project.
With the growth of WebSphere Liberty over the last few years to support the full Java EE 7 platform, itâs no more a tool confined to be used for quick development but has resulted in an increase in its adoption for final production environment deployment. Many of the solutions have been opting to migrate from âtraditionalâ WebSphere Application Server (WAS) to WebSphere Liberty.
If you are wondering how easy to get started with Liberty, then spend 2 minutes to watch the video:
Recently I have as well migrated my solution to WebSphere Liberty. During this migration, one issue I encountered is how to manage the configuration of data source, JNDI, shared libraries in server.xml so as not to clutter everything in a single long file. And moreover, I was looking for having a better control over the dynamic configuration values like database server details etc.
WebSphere Liberty provides two beautiful features to tackle both of these issues. First is you can use include elements to consolidate the configuration from different files. And second, you can specify the environment variable in the server.env file to customize the environment.
Datasource Configuration in WebSphere Liberty
Let me take an example of data source configuration to show above in action. Letâs create a server_ds_config.xml as below:
xserverx xlibrary id="db2jcc4lib"x xfileset dir="${shared.resources.dir}/db2" includes="db2jcc4.jar db2jcc_license_cisuz.jar" /x x/libraryx xdataSource id="db2DB" jndiName="MyDB" isolationLevel='TRANSACTION_READ_COMMITTED' type="javax.sql.ConnectionPoolDataSource"x xjdbcDriver libraryRef="db2jcc4lib" /x xproperties.db2.jcc serverName="${env.db2_server}" databaseName="${env.db2_dbname}" portNumber="${env.db2_port}" user="${env.db2_userid}" password="${env.db2_password}" currentSchema="${env.db2_schema}" sslConnection="${env.db2_sslconnection}" /x xconnectionManager maxPoolSize="200" minPoolSize="0" connectionTimeout="60s" maxIdleTime="3m" /x x/dataSourcex x/serverx
We can include the above data source configuration XML into the main server.xml as below:
server description="new server"x x!-- Enable features --x xfeatureManager onError="FAIL"x xfeaturexjdbc-4.1x/featurex xfeaturexlocalConnector-1.0x/featurex xfeaturexjsp-2.3x/featurex x/featureManagerx x!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" --x xhttpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/x x!-- Automatically expand WAR files and EAR files --x xapplicationManager autoExpand="true"/x xinclude location="server_ds_config.xml" /x x/serverx
And the values of the variables used can be specified in server.env file as below:
WLP_SKIP_MAXPERMSIZE=true db2_dbname=MyDB db2_password=db2inst1 db2_port=50000 db2_userid=db2inst1 db2_server=db2.server.host.name db2_schema=MyDB db2_sslconnection=false
Finally, the file structure for above configuration in WebSphere Liberty should look like below:
On a similar line, we can very well segregate configurations of JNDI specification, shared library declaration, TAI configuration, and even individual WAR configuration.
Before I close, include element provide many more attributes for configuration. It will be worth spending the time to explore them before you finalize your configurations.
Happy Exploring!!