更新Web应用程序的静态资源
我们有一个依赖于资源的 Web 应用程序 (Java
+ Tomcat
+ Spring
+ Maven
)。因此,app-1.0.1.war
依赖于resources-1.0.3.jar
。当我们需要修复资源中的bug时,我们需要
- 发布一个新的资源jar => 1.0.4
- 更新web应用的maven pom中的依赖
- 发布一个新的war => 1.0.2
- 部署 Web 应用程序
在我们团队中,有些人认为这不是一种有效的方法。他们更愿意
- 发布一个新的 jar
- 将 jar 上传到服务器上
所以基本上不需要重新部署应用程序。这看起来更容易,但我可以看到这种方法的几个问题:
- 您需要对包含资源的 jar 的名称进行硬编码。
- 您不知道应用程序正在使用的资源的版本。
更新 Web 应用程序的静态资源的常见做法是什么?
We have a web application (Java
+ Tomcat
+ Spring
+ Maven
) that depends on resources. So the app-1.0.1.war
depends on the resources-1.0.3.jar
. When we need to fix a bug in the resources, we need
- release a new resources jar => 1.0.4
- update the dependency in the maven pom of the web app
- release a new war => 1.0.2
- deploy the web app
In our team some people think that it's a not an efficient way to do. They would prefer to
- release a new jar
- upload the jar on the server
So basically no redeployment of the app. It seems easier but I can see several problems with this approach:
- You need to hard code the name of the jar that contains the resources.
- You don't know the version of the resources the app is using.
What is the common practice to update static resources of a web application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们的项目也遵循类似的方法。
这样做有很多原因,其中一些对我来说很突出:
如果这些都不适合您,请考虑阅读 依赖项版本范围。像这样的事情应该可以完成您想要做的事情:
编辑:
这是不正确的,资源只会在每次运行
mvn install
时更新 - 每次构建战争时。所以,是的,在开发过程中您将始终拥有最新的 jar,但旧的战争不会突然与最新发布的 jar 捆绑在一起。相信我,你绝对不希望这样。
您只删除了一个步骤:
您删除一个步骤会增加很多风险。查看我上面发布的链接,它可能会给您一些更合适的选择。
LATEST
可能不是您正在寻找的内容。We follow a similar approach with our projects as well.
There are a number of reason to do this, these are some of the ones that stick out for me:
If none of these apply to you, consider reading Dependency Version Ranges in the Maven documentation. Something like this should accomplish what you're trying to do:
Edit:
This is untrue, the resources would only be updated each time
mvn install
is run - every time you build a war.So yes, you will always have the most updated jar during development but an older war would not suddenly be bundled with freshly released jars on the fly. And trust me, you definitely do not want that.
You are only cutting out one step:
You're adding a lot of risk to remove one step. Check out the link I posted above, it might give you some more fitting alternatives.
LATEST
is probably not what you're looking for.