-java-maven command

Source: Internet
Author: User


The 1.Maven development process

maven is typically done in tools, and there are many tools for creating projects, such as Ecplise. How to develop with maven? Usually create a project on the tool to start writing code, all things are written in a project, so good? How do we develop it with Maven? In a project to write all things, so the things set in one place, not easy to upgrade, inconvenient to modify, inconvenient to expand, reuse. And MAVEN advocates for modular programming, we do modular programming should not be "learning Java, to the Kay Brothers School kaige123.com" All the things written in a project. MAVEN's recommendations, modular programming, a project to be disassembled into a number of modules, many sub-engineering, convenient maintenance and reuse. If all is written in a project, somewhere wrong, it is necessary to take the whole project to modify or expand, so the wrong time, will always have to modify the whole project, will be very messy. What if we use Maven? To divide a project into sub-modules, sub-projects, if a function or sub-project needs to be modified, as long as the corresponding sub-modules and sub-projects can only be modified, the other is not wrong to move, so it is more convenient. Just like a car, not a company to complete the whole vehicle manufacturing, but to split it into a number of modules, each module to the corresponding module of the most powerful companies to do, and then all the modules together is a great car. Lego, modular mobile phones and other things are used to divide a project into multiple modules of the idea of ideas. Banking Modular Development Demo: For example, our bank development is divided into three modules: 1.bank-id, Bank-banklogic, Bank-view, these three modules, we can build three MAVEN projects, Then because bank-banklogic inside need to rely on and Bank-id module, we then put Bank-id into bank-banklogic inside. And our Bank-view modules need to rely on Bank-id and bank-banklogic modules, so we should rely on the two modules, as follows:

The above is the approximate process for a project to use MAVEN engineering. The above project is divided into three modules, three projects, although the modular programming, but we hope we can have a project dedicated to all of the project's modules for unified management, unified compilation and other operations, how should we? In the future can be unified testing, unified operation, this unified way is aggregation. As Maven means to create a folder that will represent three different sub-projects of the folder inside, and then in the management Engineering directory to build a Pom.xml file to set up three sub-project management configuration information, as follows:

The file structure we want to create is as shown in a Bank-system folder with three sub-project folders and a Pom.xml file, where the Pom.xml file is used to manage the three major sub-engineering modules. Aggregation is the sub-engineering module Unified management, unified compilation, unified testing, unified operation, which is the center of aggregation. How to use Ecplise to build a unified management project?

Also set up a MAVEN project, select the pom when selecting packing, and then make aggregation settings in the Pom.xml file, such as:

Use the modules and module, to the three sub-project into the need of aggregation engineering to unified management, remember to. /bank-id this write, because these three sub-projects and Pom.xml files are not in the same directory layer, we put three sub-engineering with a project unified management, the subsequent compilation will be four projects compiled together, testing is a test. Splitting the project into separate modules is a modular programming, but the modules are really not good for unified compilation, unified testing, unified operation, so they need aggregation to create a project for unified management. If you only set the dependent junit in the Pom.xml file of the managed project, you will not share it with three sub-projects, and you will need to inherit it if you want to use JUnit below.

To use inheritance is to inherit the configuration information of the parent MAVEN project, and after inheritance, Have the parent Maven project inside the Pom.xml file set up all the things, first build a management project students-parent,packing choose Pom, remember, must choose POM, otherwise it may be wrong. Then we'll build a Maven project to inherit from it:

The global ID, skeleton ID, and version information for the parent project of the new MAVEN project are all selected:

Then, when we rely on JUnit in the Pom.xml file of the management project, Students-view inherits the Students-parent, so it will automatically have JUnit, which is the use of inheritance. Inheritance is to inherit the dependence of others, inherit other people's configuration, so that each of the following sub-projects are to write dependencies, write configuration, this saves a lot of trouble operation, the parent MAVEN project Pom.xml file content inheritance. There is a problem, as long as the sub-project inherits the management project, then each sub-project must have the parent class inside the dependency, but if my some sub-project does not want to inherit the management project all the dependence to do? It's my son. Project hope can be selective inheritance management project within the dependency, we will be forced to inherit the dependency of the sub-project to write in <dependencies></dependencies>, the optional inheritance of the dependency written in < Dependencymanagement></dependencymanagement> under:

The struts dependency in the Pom.xml file of the management project is written as a sub-project that can be selectively inherited, and then the sub-project inherits the dependency of the optional inheritance to write a version number less:

Life cycle of 2.Maven

The so-called life cycle, that is, the compilation process, is how the MAVEN project is compiled, from where to start compiling, from which block to where and so on, this is the life cycle, in order to understand, we see it as a MAVEN engineering process, it contains the project to go through all the process, Compile the process of what tasks to complete, like a pipeline, the pipeline of task operations. Three parts: 1. Clear (clean, there are three steps) 2. Default (that is, compile) 3. Site generation (sites) Cleanup: Which three steps? The first is the preparation before the cleanup, then the removal of all the files, and finally the end of the cleanup after the finishing work. Three steps is three tasks, Pre-clean, clean, post-clean, each of these three tasks are performed. Default compilation: A total of the tasks to be performed during the compilation process are:

We know that our main tasks are: Compile, test-compile, test, package, install, and so on, which is exactly the same as the one we talked about last time with Maven, that is, if we also perform the 15th bit of the test task, The 15th Test task will not be executed until the first 14 tasks have been completed. If you want to perform the deploy, you want to perform all tasks once, this is the same as the pipeline, we want to flow to the next post, then the last Post must be completed, the entire compilation has a lot of tasks, pipeline generation, write which command will go through different processes, perform different tasks. Later, if you feel the need to join a task in the compilation process is also possible, we can use the plug-in, in the existing compilation process of the task to insert some of the tasks we need to join.

As shown above, if we do the installation task, before performing this task, we will execute a JAR package, test, Testcompile, testresources, compile and other tasks, if we need to insert a task between a task, you can use the plug-in to implement. Web site Generation: MAVEN is a modular development, the development of components, write the need to publish, publish will generate a Web page, so there is a site generated this process, MAVEN can help your component to generate a presentation of the Web page, if you need to perform the site build life cycle, if you do not need to do it, This thing is generally not used. Three life cycle, each life cycle has "learn Java, to the kaige123.com" a lot of task composition, learning this we first need to understand how Maven compiled such a process is done, and secondly we want to add a task at some point in the life cycle, We'll use the plugin for this task. Inserting a plugin at some point in the life cycle is equivalent to inserting a task, and our own task is not enough. How many jobs does maven have? On the Apache website, go to the Maven page->plugin page:

We need to get a plug-in for the source package, and then insert the compilation process, so that the compilation process will package the source code instead of just hitting the jar package:

We have configured here plug-in has hit the source jar and test source jar package Two, after configuration, save and then run As–>test, get the results as shown on the right, there will be the source of the jar and test source jar package. As shown in the configuration method. You can also add a plugin to change the JDK version:

Write the configuration statement in the Pom.xml file first, then the reverse key project name->maven->update Mavne Project, and the JDK will automatically become version 1.6. You can also write the plugin to the parent MAVEN project:

Above is the Pom.xml file information for the parent MAVEN project,

Here is the Pom.xml information for the sub-project

In the management project of the Pom.xml file, anti-key->run as->test, a test, will be under the sub-project automatically hit the following package. We can also configure the package to be clean at compile time, such as:

-java-maven command

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.