In this article I’m going to present a solution for hosting a single page application using HTML5 / client-side routing in a Java web application. This is not easily supported out of the box, so I thought it would be helpful to write a dedicated article that presents a ready-to-use solution.
Traditionally routing is done server-side. The server receives a HTTP request, determines which page of the application is requested and then renders that page itself.
In this article I’m going to present a simple configuration solution for small to medium-sized applications running in Tomcat. It uses only the configuration mechanism that Java and Tomcat provide out-of-the-box, requires minimal code and supports multiple installations.
Most applications need some sort of environment-specific configuration. Depending on the environment (Test, Prod, Customer-specific…) you usually have different databases, use different API endpoints or different accounts for accessing a resource. …
However there are cases where it can be beneficial to use conditional compilation instead.
Traditionally it is a technique that is often used is when compiling native executables for different platforms or architectures. In this scenario you want the executable to only include instructions that are available on that platform.