我有网络应用程序。我正在使用 maven 来构建这个应用程序。我在构建应用程序时得到一个 war 文件:my-service-1.0.0-SNAPSHOT.war。通过 http 访问服务时,我必须这样调用:
http://localhost:8080/my-service-1.0.0-SNAPSHOT/......
我不想在上下文名称中使用版本号。我正在使用 tomcat 作为容器。我是否必须像在 jboss 的情况下那样在 Web-Inf 下为此设置上下文根?这取决于我们使用的容器类型吗?
最佳答案
使用 Maven,您可以在 pom.xml 文件中设置一个变量来存储您的最终构建名称,并在您的 war 插件配置中传递它。像这样:
<build>
<finalName>my-service</finalName>
</build>
然后在你的插件配置中:
<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>
关于java - 避免来自 Web 应用程序上下文根的版本号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19123825/