1

Is there any possible way that we can deploy two war file(same project) with same name in tomcat.

I have app which has the URL app/customer/123 which return me the customer details, now I want to give the version like app/v1/customer/123 should give me the customer details. This is typically the version maintenance. There are other way for version maintenance which are covered in below post Best way to maintain api version

but again I have to write lot of code. I was looking for something i can provide immediate solution(later on i can follow the best practice and do the changes) I was thinking if i could deploy two war file with same name by just changing the <url-pattern>/v1/*<url-pattern> so customer can access the both api by just adding the version in the URL(This will prevent changing the whole URL)

I tried this also but this did not work How to deploy external webapp in tomcat?

Is there any way i can achieve this?

Varun
  • 4,342
  • 19
  • 84
  • 119

1 Answers1

1

1) You can deploy different versions of your app on different context paths like this:

apache-tomcat/conf/Catalina/localhost/app#v1.xml:

<Context docBase="c:\path\to\v1\app.war" path="/app/v1"/>

Accessible via http://localhost:8080/app/v1

apache-tomcat/conf/Catalina/localhost/app#v2.xml:

<Context docBase="c:\path\to\v2\app.war" path="/app/v2"/>

Accessible via http://localhost:8080/app/v2

2) You can deploy a single war file multiple times on different context paths like this:

apache-tomcat/conf/Catalina/localhost/app#v1.xml:

<Context docBase="c:\path\to\app.war" path="/app/v1"/>

Accessible via http://localhost:8080/app/v1

apache-tomcat/conf/Catalina/localhost/app#v2.xml:

<Context docBase="c:\path\to\app.war" path="/app/v2"/>

Accessible via http://localhost:8080/app/v2

See Apache Tomcat Context Configuration Docs for details.

Selaron
  • 6,105
  • 4
  • 31
  • 39
  • Do I need to append # in the file name app#v1.xml? – Varun Jan 21 '19 at 15:45
  • As described in the linked documentation the file name has to match the context path, while '/' in context path is represented by '#' in the config file name. – Selaron Jan 21 '19 at 15:55
  • It is always taking the latest version – Varun Jan 21 '19 at 16:25
  • I'm not sure what you mean with "It is always taking the latest version". Can you edit your question and point out what Tomcat Manager Application List is showing and what you would expect it to show? @Varun – Selaron Jan 31 '19 at 21:15