How to set context path to non spring java applications to work on cloud foundry tomcat container?
The syntax that you have should work. I tested cf set-env JBP_CONFIG_TOMCAT '{tomcat: {context_path: "/spring-music"}}'
and it worked OK. You can also use cf set-env JBP_CONFIG_TOMCAT '[tomcat: {context_path: "/spring-music"}]'
which worked for me too.
Example using manifest.yml
:
---
applications:
- name: spring-music
memory: 512M
host: spring-music-example
path: build/libs/spring-music.war
env:
JBP_CONFIG_TOMCAT: '[tomcat: {context_path: "/spring-music"}]'
This results in Spring Music being available at http://spring-music-example.example.com/spring-music, instead of the default http://spring-music-example.example.com/.
This also works very nicely in conjunction with path based routing (i.e. cf push --route-path
or or cf create-route --path
.
If it's not working:
- Check that you've restaged your app or applied the change via
cf push
.
- Check that you're using a recent version of the Java build pack. I tested with 3.14 and it worked.
- Check your version of the Java build pack's
config/tomcat.yml
file (i.e this). This file defines the hierarchy of the config options and has occasionally changed. Make sure what you're setting matches that file in your version of the build pack.
Hope that helps!