Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the context path of deployed (Spring Boot) war on a container tomcat server. So it is not demo-0.01-SNAPSHOT

I have tried to deploy my site using many configurations to make it change from the war name being deployed. Is there a way to do this easily. The deployment will to a tomcat sitting somewhere else. e.g. bitnami instance

I have tried various combinations of settings in the application.properties but none make any difference:

 server.servlet.context-path=/a
    server.servlet.path=/b
    spring.webservices.path=/c
    server.contextPath=/m

The war is called demo-0.0.01-SNAPSHOT.war and when dropped in the webapps directory it creates the same named directory and the site then has a /demo-0.0.01-SNAPSHOT path. I thought with the days of Spring Boot this would be easy now but a fool like me hasn't worked it out yet. Or do people just deploy embedded versions with tomcats and run them nowadays?

(BTW I have tried the root.xml as well, no luck ... unless i did it wrong on my windows box, testing on my dev box first, linux for deployment)

Any help would be appreciated.

Thanks

like image 366
Denis Avatar asked May 08 '17 19:05

Denis


Video Answer


2 Answers

The Spring Boot property to specify the context path of the application is : server.contextPath.
But the fact that you are deploying your WAR into a standalone Tomcat instance doesn't allow to use it.
In this configuration, you cannot use server.contextPath and other properties specific to the container (as for example server.port). These are designed to work with the embedded Tomcat instance.

The standalone Tomcat instance keeps indeed the control on these facilities provided by Spring Boot. So you have to configure it from the configuration file of the standalone Tomcat (server.xml or ROOT.xml way generally).

like image 154
davidxxx Avatar answered Oct 17 '22 04:10

davidxxx


Adding finalName setting to pom.xml for maven will make the packaged war filename to it. For example.

<build>
...
<finalName>myapp</finalName>
</build>

The packaged filename will be myapp.war . When you deploy to tomcat it will set the context to the filename.

like image 42
acpuma Avatar answered Oct 17 '22 04:10

acpuma