简体   繁体   English

何时使用mvn clean install而不是mvn install?

[英]When to use mvn clean install instead of mvn install?

I have a web application that is packaged as a war file ( including several jar files ). 我有一个打包为war文件的Web应用程序(包括几个jar文件)。 I noticed that when I run mvn install - the only projects that are compiled are those who have changed - then it replaces these jar s in the war file. 我注意到当我运行mvn install时 - 编译的唯一项目是那些已经更改的项目 - 然后它会替换war文件中的这些jar

If that's the case - when should I use mvn clean install instead of simply use mvn install? 如果是这种情况 - 何时应该使用mvn clean install而不是简单地使用mvn install?

I guess that if I change any resources than I would have to use mvn clean install - Am I right? 我想如果我改变任何资源而不是使用mvn clean install - 我是对的吗?

And if I'm right, then whenever I only change classes, is mvn install good enough? 如果我是对的,那么每当我只改变课程时,mvn安装是否足够好?

Mostly, the only reason to do a clean is if you do something that would remove or rename a class or resource in the output directory, such as renaming a .java file or changing something that generates classes so that it generates them with different names. 大多数情况下,执行清理的唯一原因是,如果您执行的操作会删除或重命名输出目录中的类或资源,例如重命名.java文件或更改生成类的内容,以便使用不同的名称生成类。 In those cases, the old class or resource files will still exist in the output directory and may cause strange behavior. 在这些情况下,旧的类或资源文件仍将存在于输出目录中,并可能导致奇怪的行为。

Other than that, just use install, and you'll be fine. 除此之外,只需使用安装,你会没事的。 Then Maven will only build what needs to be built to bring the output directories up to date. 然后,Maven将只构建需要构建的内容以使输出目录更新。

Use clean when you want to build your projects from scratch. 如果要从头开始构建项目,请使用clean。 If your build does not take a lot of time use clean every time you are running build. 如果你的构建不需要花费很多时间,那么每次运行build时都要使用clean。 Otherwise it is up to you. 否则取决于你。

Surely do it if you are not sure that everything is indeed updated. 如果你不确定一切都确实更新了肯定会这样做。

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

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