3

I've web application. I'm using maven to build this application. I get a war file when i build application: my-service-1.0.0-SNAPSHOT.war. While accessing the services over http, i have to make a call like this:

 http://localhost:8080/my-service-1.0.0-SNAPSHOT/......

I don't want version number in my context name. I'm using tomcat as container. Do i have to set context root for this under Web-Inf as we do it in case of jboss ? Does it depend based on the type of container we use ?

iskramac
  • 868
  • 6
  • 14
Pankaj
  • 3,512
  • 16
  • 49
  • 83
  • You can set the context path on Tomcat: http://stackoverflow.com/questions/7276989/howto-set-the-context-path-of-a-web-application-in-tomcat-7-0 – Anthony Accioly Oct 01 '13 at 19:29
  • And you can also use the `path` configuration if you are using tomcat maven plugin: http://stackoverflow.com/a/7811435/664577 – Anthony Accioly Oct 01 '13 at 19:35
  • This should not matter because this is in-place container in Maven. This is not intended for production! – Michael-O Oct 01 '13 at 19:46
  • Is there any way to handle it in application itself rather than configuring at container level ? I don't want to rename the war file as suggested using maven (build file name). – Pankaj Oct 01 '13 at 21:23

2 Answers2

4

Using maven you can set a variable in your pom.xml file to store your final build name and in your war plugin configuration you pass it. Something like this:

<build>
  <finalName>my-service</finalName>
</build>

Then in your plugin configuration:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-war-plugin</artifactId>
     <version>2.0</version>
     <configuration>
           <webappDirectory>/path_to_deploy_folder/${project.build.finalName}.war</webappDirectory>
     </configuration>
 </plugin>
Jorge Campos
  • 22,647
  • 7
  • 56
  • 87
1

You did not mention whether you are using maven to deploy into tomcat container. If you're creating a production environment you probably won't be using maven at least for local deployments. In that case I don't think it's a bad idea to rename your war file. For example if you want you webapp root to be at https://mydomain.com/subdomain/myteam/myapp then simply rename my-service-1.0.0-SNAPSHOT.war to subdomain#myteam#myapp.war with '/' being replaced by '#'

The Governor
  • 1,152
  • 1
  • 12
  • 28