简体   繁体   English

Mvn安装或Mvn包

[英]Mvn install or Mvn package

I am new to Maven, I have a Java based web project with maven configured in my MyEclipse. 我是Maven的新手,我有一个基于Java的web项目,我的MyEclipse中配置了maven。
Now if I modified any java files then do I need to do Run as -> Mvn install or Mvn package ? 现在,如果我修改了任何java文件,那么我是否需要Run as -> Mvn installMvn package

from http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html 来自http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

package : take the compiled code and package it in its distributable format, such as a JAR. package :获取已编译的代码并将其打包为可分发的格式,例如JAR。

install : install the package into the local repository, for use as a dependency in other projects locally install :将软件包安装到本地存储库中,以便在本地用作其他项目的依赖项

So the answer to your question is, it depends on whether you want it in installed into your local repo. 所以问题的答案是,这取决于您是否希望将其安装到您的本地仓库中。 Install will also run package because it's higher up in the goal phase stack. 安装也将运行包,因为它在目标阶段堆栈中更高。

mvn install is the option that is most often used. mvn install是最常用的选项。
mvn package is seldom used, only if you're debugging some issue with the maven build process. 只有当您使用maven构建过程调试某些问题时,很少使用mvn package

See: http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html 请参阅: http//maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

Note that mvn package will only create a jar file. 请注意, mvn package只会创建一个jar文件。
mvn install will do that and install the jar (and class etc.) files in the proper places if other code depends on those jars. 如果其他代码依赖于这些jar, mvn install将执行此操作并将 jar(和类等)文件安装在适当的位置。

I usually do a mvn clean install ; 我通常做一个mvn clean install ; this deletes the target directory and recreates all jars in that location. 这将删除target目录并重新创建该位置中的所有jar。
The clean helps with unneeded or removed stuff that can sometimes get in the way. 清洁有助于消除不必要或被移除的东西,有时可能会妨碍。
Rather then debug (some of the time) just start fresh all of the time. 而不是调试(有些时候)只是一直开始新鲜。

From the Lifecycle reference , install will run the project's integration tests, package won't. Lifecycle引用中install将运行项目的集成测试, package不会。

If you really need to not install the generated artifacts, use at least verify . 如果您确实不需要安装生成的工件,请至少使用verify

另外你应该注意,如果你的项目由几个相互依赖的模块组成,你应该使用“install”而不是“package”,否则你的构建将失败,因为当你使用install命令时,模块A将被打包并部署到本地存储库,然后如果模块B需要模块A作为依赖项,它可以从本地存储库访问它。

If you're not using a remote repository (like artifactory), use plain old: mvn clean install 如果您没有使用远程存储库(如artifactory),请使用plain old: mvn clean install

Pretty old topic but AFAIK, if you run your own repository (eg: with artifactory) to share jar among your team(s), you might want to use 相当古老的主题,但AFAIK,如果您运行自己的存储库(例如:带有神器)在您的团队之间共享jar,您可能想要使用

mvn clean deploy

instead. 代替。

This way, your continuous integration server can be sure that all dependencies are correctly pushed into your remote repository. 这样,您的持续集成服务器可以确保将所有依赖项正确地推送到远程存储库中。 If you missed one, mvn will not be able to find it into your CI local m2 repository. 如果您错过了一个,mvn将无法在您的CI本地m2存储库中找到它。

package - takes the compiled code and package it in its distributable format, such as a JAR or WAR file. package - 获取已编译的代码并将其打包为可分发的格式,例如JAR或WAR文件。 install - install the package into the local repository, for use as a dependency in other projects locally install - 将软件包安装到本地存储库中,以便在本地用作其他项目的依赖项

The proper way is mvn package if you did things correctly for the core part of your build then there should be no need to install your packages in the local repository. 正确的方法是mvn package如果你为构建的核心部分做了正确的事情,那么就不需要在本地存储库中安装你的包。

In addition if you use Travis you can "cache" your dependencies because it will not touch your $HOME.m2/repository if you use package for your own project. 此外,如果您使用Travis,您可以“缓存”您的依赖项,因为如果您为自己的项目使用包,它将不会触及您的$HOME.m2/repository

In practicality if you even attempt to do a mvn site you usually need to do a mvn install before. 实际上,如果您甚至尝试创建一个mvn site ,通常需要先mvn install There's just too many bugs with either site or it's numerous poorly maintained plugins. 任何一个site存在太多错误,或者有许多维护不良的插件。

It depends on what you're trying to achieve after changing the Java file. 这取决于您在更改Java文件后尝试实现的目标。 Until you want to test the maven process, you never need to do anything. 在您想要测试maven进程之前,您永远不需要做任何事情。 Eclipse/MyEclipse will build what is necessary and put the output in the appropriate place within your project. Eclipse / MyEclipse将构建必要的内容并将输出放在项目中的适当位置。 You can also run or deploy it (if it's a web project, for example), without your needing to explicitly do anything with maven. 您也可以运行或部署它(例如,如果它是一个Web项目),而无需使用maven明确地执行任何操作。 In the end, to install your project in the maven repository, you will need to do a maven install. 最后,要在maven存储库中安装项目,您需要进行maven安装。 You may also have other maven goals that you wish to execute, which MyEclipse won't do automatically. 您可能还有其他希望执行的maven目标,MyEclipse不会自动执行这些目标。

As I say, it depends on what you want to do. 正如我所说,这取决于你想做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM