What does maven do ?, Maven is
I have recently studied background-related things, although I still don't know much about the frontend ~ But the computer did not write background code for a year, so I am about to stop it ~ Emmmmm... they always talk to me about maven, Grace, so let's see what it is? I pulled an article from zhihu, a gathering of great gods ~ Archiving: Author: Guo unintentionally
Link: https://www.zhihu.com/question/20104186/answer/73797359
Source: zhihu
Copyright belongs to the author. For commercial reprint, please contact the author for authorization. For non-commercial reprint, please indicate the source.
http://suhuanzheng7784877.iteye.com/blog/1066917
1. Preface
Maven is a top-level project of apache. Its appearance is increasingly affecting a large number of open-source projects. In addition, many new projects of many companies are managed in the way promoted by Maven. Maven is gradually intruding into our original habits of managing projects. It is a great leap in team management and project construction. Of course, this is my personal project experience. If the old team leader is very scientific in management, there is also a set of mechanisms to assist the construction, packaging, and release of other software projects. Maven may have no substantial impact on it or a qualitative leap. Of course, this does not mean that the projects developed by Chinese people are not well managed ...... It just means that Maven can help us build projects that are more scientific, more maintainability, more modular, more functional modules, and more reusable projects. Of course, I am also a person who has just learned Maven. Let's learn what benefits Maven brings to us. The author's email address has been provided. You are welcome to have academic exchanges with the author.
2. Maven ideas
I wanted to finish reading the entire article and write a summary later. I thought I should write it first. Even if there is something wrong, it's not too late to correct it. I'm afraid that I will not have any experience after reading it. It's too much to forget it ...... Therefore, we should first write down the learning experience and then repeat it with examples.
The main functions of Maven are as follows:Project Construction; project construction; Project dependency management; continuous integration of software projects; version management; site description management of the project;
From this we can see which two words are mainly embodied in Maven? -- By the way, "project" and "management "! Project management is used together. Project management is a very abstract concept. Project management can refer to both technical management methods and non-technical factors that are "people-oriented. It is true that, whether it is technical or non-technical, the project's biggest responsible person is actually the project manager. Here we leave aside human factors. Technically speaking, Maven provides an idea for teams to manage and build projects more scientifically. Describes the project description, name, version number, project dependency, and other information in the configuration file. The project description structure is clear, and the cost for anyone to take over is relatively low. When building a project, Maven's idea of "convention is greater than configuration" can save a lot of configuration file content than Ant scripts. In addition, a project may depend on other projects and third-party components before it can be successfully completed. Maven provides the concept of a repository, allowing these dependencies to be put into the repository, and the project wants to be retrieved from the repository, other project teams also need to, OK, fetch from the warehouse, so no one has to go to the site of the open-source project to search for it. The cost of personnel, software maintenance, communication, and hardware are all reduced. The customer smiled, the company boss smiled, the project manager smiled, the team members laughed, and so many people in the Apache community laughed. I feel that the open source is moving closer and closer to "Agile development" and "Extreme Programming. Through Maven-assisted project management, you can find out which modules in the project are repetitive.
3. Build a Maven Environment
Let's take a look at how to build the Maven environment. Download Maven from the Apache website. Download url: http://maven.apache.org/download.html. I downloaded Maven 3.0.3. The downloaded package structure is as follows:
Bin doesn't need to be said, that is, some command parameters of Maven. The boot contains the Maven class loader, so we don't have to worry about it. Conf contains settings. xml, which is the configuration information of Maven on the local machine. Lib is the class library required for running Maven. Set the bin directory as the bin directory of JDK to the PATH of the system. In this way, you can directly run the Maven command on the command line.
Keep the network open and execute a Statement on the command line.
Java code
Many items will be downloaded from the Internet. A temporary Maven file directory will be generated for the local user's temporary folder to store the local resource warehouse. For example, there is a folder named. m2 under C: \ Users \ liuyan.
Copy the settings. xml file you just mentioned to C: \ Users \ liuyan \. m2. Maven is installed on the local machine.
I used Myeclipse8.6 for the selection of development tools. This IDE has integrated the Maven plug-in Maven4Myeclipse. You only need to configure the overall configuration information. In Myeclipse, click the window menu to open the preferences option. Click the maven4myeclipse node of myeclipse, as shown in.
4. Get started with Maven
First, we need to write a very simple small project (we call it a project). The project structure is shown in.
Src. main. java is the project code folder, src. test. java is the project unit test folder, and src. main. resource is the project resource file and configuration file folder. The project code is as follows:
A simple class of com. liuyan. maven. helloword. HelloWorld
Java code
There is a pom. xml file under the root directory of this project. The content is as follows:
Java code
Go to the console and cd the current directory to a folder at the same level as pom. xml. Execute Command
Java code
Because the author downloaded the relevant package before writing the summary, at this time the relevant output download package information is less
Java code
Result After execution. Is a taget folder under the root path of the project.
It is the compiled class. The manager said that you need to perform a unit test to release it to everyone. OK. Let's write the junit unit test class under the source code package-src/test/java.
The unit test code is as follows:
Java code
Since junit unit test is used, our project depends on it. Modify the content of the pom. xml file as follows:
Java code
Go to the command line and execute the command
Java code
After the execution, observe the taget folder, such as the test-classes folder and the other two folders that we don't need to worry about temporarily.
Then, observe the local temporary warehouse C: \ Users \ liuyan \. m2 \ repository. The extra folder junit will be displayed. The downloaded version is 4.7.
What if we want to output the project as a jar? Run
Java code
The results are as follows:
A jar package is generated. As for SNAPSHOT, SNAPSHOT means that the project is not stable yet.
It's okay after testing and packaging. If you want to use this project as a Maven Local Resource Repository and provide services for other projects, you can do this.
Execute Command
Java code
After the execution, the local temporary library file has more than your own project. In this way, other projects can extract the corresponding jar from the local Mavne library when you need this project to provide services.
5. Use IDE To build the POM. xml skeleton
The current form is as follows. Although Maven is in full swing, there are still many defects in various IDE plug-ins that support Maven. The so-called name is not regular, and the open-source projects not supported by IDE are always "non-mainstream, for example, a simple command can be successfully executed in the doscommand line just now. How can this problem be solved in Myeclipse. I only use IDE To build the pom. xml file here, because I personally feel that it is not very significant to execute Maven commands using IDE, because Maven commands need to be manually executed in linux.
The Myeclipse tool can provide developers with visual editing of the POM. xml file.
6. Summary
This is an opening. This time I only introduced Maven's Environment setup and getting started commands, and I also learned some Maven ideas. Later, we will combine the small cases in the book to learn the features of Maven step by step.