我们为什么要部署应用程序?
我真的不明白这个mvn部署
,为什么我们要这样做?
我做
mvn clean install
然后我做
mvn jetty:run
我只是有点困惑为什么我们需要这样做或者我应该偶尔进行部署。
I don't really get this mvn deploy
and why do we do it?
I do
mvn clean install
Then i do
mvn jetty:run
I am just bit confused on why do we need to do this or should i do deployment once in a while.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简而言之,Maven 从本地存储库(通常为 $HOME/.m2/repository)解析工件(您放入依赖项部分的工件)。如果它在本地存储库中找不到该工件,它将查找远程存储库。标准远程存储库是位于 http://repo1.maven.org/maven2 的“中央”存储库。
如果执行“mvn install”,您将告诉 Maven 将您的工件(目标文件夹中的 WAR)复制到本地存储库。现在您的其他 Maven 项目可以解析该工件。
如果您希望其他人能够解析该工件,您需要将其放在远程存储库上。这是通过“mvn deploy”完成的(就像中央存储库一样,您可以创建自己的远程存储库)。
为了部署您的 Web 应用程序,您需要从目标文件夹手动部署 WAR 文件,或者使用 Cargo 等 Maven 插件部署到应用程序服务器。
当 WAR 文件通常不用作其他项目中的依赖项时,将 WAR 文件部署到远程 Maven 存储库有何意义?
我建议在应用程序服务器上部署某些内容之前,先正确发布代码。有一个发布插件可以帮助您做到这一点。除了将其放在远程 Maven 存储库之外,它还标记 SCM 中的当前源(例如 subversion)。现在,您的 Maven 存储库中有一个版本控制的二进制文件,它与 SCM 中的标记版本相匹配。
由于 Maven 存储库具有明确定义的结构,因此可以轻松编写将新版本拉取到生产服务器的脚本。
Simply put Maven resolves artifacts (the ones you put in the dependencies section) from a local repository (typically $HOME/.m2/repository). If it cannot find the artifact in the local repository it will look i a remote repository. The standard remote repository is the "central" repositrory at http://repo1.maven.org/maven2.
If you execute "mvn install" you tell Maven to copy your artifacts (your WAR in the target folder) to the local repository. Now your other Maven projects can resolve the artifact.
If you want others to be able to resolve the artifact you need to put it on a remote repository. This is done with "mvn deploy" (just like the central repository, you can create your own remote repository).
In order to deploy your web application you need to either manually deploy the WAR file from the target folder or use a Maven plugin like Cargo to deploy to the application server.
What is the point of deploying WAR files to a remote Maven repository, when they usually are not used as dependency in other projects?
I would suggest that prior to deploying something on the application server you do a proper release of your code. There is a release plugin that helps you with that. In addition to putting it on the remote Maven repository it tags the current source in your SCM (e.g. subversion). Now you have a versioned binary in your Maven repository that matches a tagged version in your SCM.
Since the Maven repository has a well-defined structure it is easy to write scripts that pull a new version to the production server.
Maven 部署插件 摘录:
与
Maven 安装插件 摘录
Maven Deploy Plugin Excerpt:
versus
Maven Install Plugin Excerpt