On Java Development

All things related to Java development, from the perspective of a caveman.

Using ${catalina.home}

without comments

Introduction

This post shows how ${catalina.home}, which is set by the application server, can be leveraged to prevent hard-coding of paths. In the event that the application is moved to another server, which is the case when servers are upgraded, the application does not have to be modified and moved as-is.

In a Spring Context File (applicationConfig.xml)
This shows how ${catalina.home} is used to establish a path segment used to designate the location of an application resource such as a PDF file.

There are 3 beans defined in the context file; one to contain values used when running on the developer’s machine (localhost), one to contain values used when running on the test server (TEST) and one to contain values used when running on the production server (PROD).

The path for localhost is static and unique to the developer’s machine, so it is a static value. The paths for TEST and PROD differ depending upon the server in which the application is running. To get the home directory of the server, ${catalina.home} is used which returns the proper value for that server.

When the application is running on the TEST server, the value for approvalPDFFileLocation is resolved as “/Tomcat/Tomcat7028T/webapps/appcontent/ClaimsCheckApproval/

Written by admin

April 1st, 2014 at 12:20 pm

Leave a Reply

You must be logged in to post a comment.