Maven install, build, Clean_ editing tools for MAVEN projects in eclipse

Source: Internet
Author: User
Tags pack

When I made a war package for the MAVEN project, first it was maven clean, then there was an error in the Maven build, saying that I couldn't find the target file for the project (I don't copy it in English) and I spent a lot of time on it, and finally maven Install, I feel very puzzled, I did not have a deep understanding of maven before, but the usual reference to a jar bag, playing a war package, and so on, this situation was really very crazy to me, so it can be checked on the Internet, for the above problems do a summary, For you and me he looked at:


Standard MAVEN Project Package hierarchy:

-project

--src/main/java

--src/main/resources

--src/test/java (if you are using-dskiptests, the test classes are compiled, but not if you check skip tests)

--src/test/resources (if the-dskiptests is used, the resource files are compiled, but if skip tests is checked)


The above is a description of the use of the command in Eclipse;

1, Maven Clean is to clear the target directory before the dozen Jar pack or the war package;

2. The Maven build is a new package for the MAVEN project, where you need to manually enter the packaged command-X package

The top two commands are together. Maven install is a collection of the above two commands, both through the native commands of Maven, while the clean and build are executed, saving time;

So that's the question. Why did I make a mistake when I did it alone, which means that Maven is unfriendly to the eclipse-take plug-in execution;

Here is a summary of another question of the great God;

Before the process of writing code has encountered problems, with MVN install, the new modified content does not take effect, must later use MVN clean install only effective, so want to see the difference between clean and not clean.


As you know, MAVEN will perform all of the previous lifecycle operations, such as executing mvn install, performing the previous sequence of actions, including compile, package, test, and so on, in the execution of a lifecycle command, please see the official documentation for MAVEN. This feature makes Maven's commands more concise and easy to use.

To analyze the original problem, why the modified content does not work, is definitely the end of the war package is not updated, and the war package will rely on other child engineering jar package, if the jar package has not been updated, the war package calls the old jar package will also cause the new content does not take effect. The reason to navigate to the problem should be that the jar package is not using the latest resources (Java or configuration files), and when and who is going to hit the jar pack.

We mentioned above that we would execute the MVN install first by performing the MVN Package,maven is to package (war, jar, or other) according to the user's configuration, which will be set up in each project Pom.xml file, similar to the following:

<project xmlns= "http://maven.apache.org/POM/4.0.0"
  xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemalocation= "http://maven.apache.org/POM/4.0.0

http://maven.apache.org/xsd/maven-4.0.0.xsd" > ...
  <packaging>war</packaging> ...
</project>

When package is designated as a war package, the jar is called a jar package.

As we look at the jar form, MVN package will call Maven-jar-plugin this plugin for packaging.
Now let's do some experiments to see what happens when this plugin is packaged.

1. Modify the contents of class and configuration file in the jar package in the target directory, and the contents of the target package are not overwritten when the command MVN package run.
2. Modify the contents of the source code, and then run the command MVN package, the result of the target package content is overwritten, resulting in a new package.
3. Modify the contents of the jar pack in the target directory and run the command mvn package-djar.forcecreation, which should be forced to create the jar package, so the jar package content in the result target is overwritten and a new jar package is generated.

Depending on the experiment above, it seems to be impossible to explain when clean will remove the contents of target from the regeneration, jar package, but at least some rules are understood. Summary
1. Theoretically not doing mvn clean the jar pack should be up to date unless you modify the contents of the jar package in other ways without modifying the source code.
2. You can use MVN install instead of Chean to save time (if you think it saves time), but the most insurance is to use MVN clean install to generate the latest jar packs or other packages
3. Don't want to use MVN Clean also wants to keep the jar pack up to date, recommend adding  -Djar.forceCreation  parameters

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.