Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom context path in external tomcat

I made a Spring-Boot application that I want to run in an external tomcat 8.

In a Spring-Boot application , the context-path can be chosen using the property server.context-path in application.properties but as I am using an external tomcat 8, this property is not used.

Hence, I took a look at the tomcat-8 documentation which states:

If you want to deploy a WAR file or a directory using a context path that is not related to the base file name then one of the following options must be used to prevent double-deployment:

  • Disable autoDeploy and deployOnStartup and define all Contexts in server.xml
  • Locate the WAR and/or directory outside of the Host's appBase and use a context.xml file with a docBase attribute to define it.

As I do not want to pollute server.xml, I chose the second option. Hence, I located the war in /home/myuser/myapp/application-1.0.0.war and I placed a context file name application-1.0.0.xml under conf/Catalina/localhost. This file contains only those 2 lines :

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/myapp" docBase="/home/myuser/myapp"/>

I can see in the logs that tomcat8 starts successfully, the application appears to be deployed in the tomcat manager but :

  • The path is /application-1.0.0 instead of /myapp.
  • Moreover, a directory application-1.0.0 appears in the work directory but stays empty.
  • The logs does not show any spring related logs as if the application had never been initialized.

Note : I know that the war is correct because it works if I place it in the webapp directory (with the default context path though).

Note : If I rename application-1.0.0.xml to foo.xml, the tomcat manager shows that the application is deployed under context-path /foo (but it is still never started).

Any ideas?

like image 947
Arnaud Denoyelle Avatar asked Oct 30 '22 19:10

Arnaud Denoyelle


1 Answers

Found the answer :

  • Concerning the context-path, the attribute path of the context file is indeed ignored :

This attribute must only be used when statically defining a Context in server.xml. In all other circumstances, the path will be inferred from the filenames used for either the .xml context file or the docBase.

  • Concerning the docBase attribute, I misinterpreted the following sentence :

Locate the WAR and/or directory outside of the Host's appBase and use a context.xml file with a docBase attribute to define it.

Actually, in docBase, I put the path to the directory which contains the war instead of the path to the war itself.

like image 150
Arnaud Denoyelle Avatar answered Nov 15 '22 11:11

Arnaud Denoyelle