Configuration Management of WebSphere Liberty for production environment
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<server> <library id="db2jcc4lib"> <fileset dir="${shared.resources.dir}/db2" includes="db2jcc4.jar db2jcc_license_cisuz.jar" /> </library> <dataSource id="db2DB" jndiName="MyDB" isolationLevel='TRANSACTION_READ_COMMITTED' type="javax.sql.ConnectionPoolDataSource"> <jdbcDriver libraryRef="db2jcc4lib" /> <properties.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}" /> <connectionManager maxPoolSize="200" minPoolSize="0" connectionTimeout="60s" maxIdleTime="3m" /> </dataSource> </server> |
We can include the above data source configuration XML into the main server.xml as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
server description="new server"> <!-- Enable features --> <featureManager onError="FAIL"> <feature>jdbc-4.1</feature> <feature>localConnector-1.0</feature> <feature>jsp-2.3</feature> </featureManager> <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" --> <httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/> <!-- Automatically expand WAR files and EAR files --> <applicationManager autoExpand="true"/> <include location="server_ds_config.xml" /> </server> |
And the values of the variables used can be specified in server.env file as below:
1 2 3 4 5 6 7 8 9 |
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!!