In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is to share with you about the order in which multiple sub-modules are built in maven. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Construction sequence of multiple sub-modules of maven
In the actual project development, in order to better organize the project code, the hierarchical architecture will be adopted, which will use the multi-module feature of maven.
Suppose the project is divided into four layers A, B, C and D. In the pom.xml of the parent module, the sub-modules are generally aggregated in this way.
A B C D
Suppose the configuration interdependencies between the submodules are as follows:
A depends on B
B depends on C
D depends on A
By building the parent module, we can see the following output:
[INFO]
[INFO] Reactor Build Order:
[INFO]
[INFO] C
[INFO] B
[INFO] A
[INFO] D
[INFO]
[INFO]
This is because the construction order of sub-modules is affected by two factors.
1. The declaration order of each child module in the parent module
2. Dependencies between sub-modules
The actual build order is formed in this way
Maven reads the pom in order, and if the pom does not rely on other submodules, it builds the module, otherwise it builds the dependent module, and if the dependent module depends on other modules, then further builds the dependent dependency.
In the example, the A module depends on B, and the B module depends on C, so you have to build C and B before you can build A. Module A that D depends on has already been built, so build it directly.
The dependency relationship between modules will form a directed acyclic graph of the reactor (Reactor). Each module is the node of the graph, and the dependency relationship forms a directed edge. Loops are not allowed in this diagram. If A relies on both B and A, there is a circular dependency and Maven will report an error.
Build in maven 1. What is build?
Building is not creating, and creating a project is not the same as building a project. To understand the meaning of building, we should look at it from the following three levels:
(1) Pure Java code (compiled)
As we all know, Java is a compiled language, and the source file of the. java extension needs to be compiled into a bytecode file with a .class extension to execute. So writing any Java code that you want to execute must be compiled to get the corresponding. Class file.
(2) Web Project (deployment)
When we need to access the Java program through the browser, we must "get" the compiled results of the Web project containing the Java program to the specified directory on the server and start the server. The process of "taking" is called deployment. We can compare the uncompiled Web project to a raw chicken, the compiled Web project is a cooked chicken, and the process of compilation and deployment is to stew the chicken.
Note: the classpath used in the development process or configured in the configuration file is based on the file structure of the compilation results.
(3) actual project
In the actual project, the integration of third-party framework, Web project in addition to Java programs and JSP pages, pictures and other static resources, but also includes the third-party framework jar package and a variety of configuration files. All of these resources must be deployed to the server according to the correct directory structure before the project can run.
So to sum up: building is the process of using static resources such as Java code, framework configuration files, internationalization and other resource files, JSP pages and pictures as "raw materials" to "produce" a project that can be run.
two。 Several main links in the construction process
(1) cleanup: delete the previous compilation results and prepare for recompilation.
(2) compilation: compile the Java source program into a bytecode file.
(3) testing: test the key points in the project to ensure the correctness of the key points in the iterative development process.
(4) report: record and display test results in a standard format after each test.
(5) Packaging: encapsulate a project containing many files into a compressed file for installation or deployment. Java project corresponds to jar package, and Web project corresponds to war package.
(6) installation: in the Maven environment, it specifically means to install the packaged result-jar package or war package into the local warehouse.
(7) deployment: deploy the packaged results to the remote warehouse or deploy the war package to the server to run.
3. Automatic construction
In fact, the above links we can find the corresponding operation in Eclipse, but not very standard. So why use a build tool like Maven when IDE is ready to build?
Let's take a look at a short story to learn about:
It's a sunny day. Thomas arrived at the company early as usual, made a cup of coffee and entered his mailbox-unfortunately, the QA team sent an email reporting the test results of the module he submitted yesterday-BUG. " Well, it's not the first time, "Thomas shook his head, went into IDE, ran his own program, compiled, packaged, deployed to the server, and then tested according to the path in the email." "well, yes, there is something wrong with this place," Thomas said. So Thomas began to try to fix the BUG, and by the time he was almost ready, it was lunchtime. Get back to work in the afternoon. BUG was quickly fixed, and Thomas recompiled, packaged, and deployed the module, confirmed that there was no problem after testing, and responded to an email from the QA team. The day passed in this way, and the bright sunshine turned into a beautiful sunset, but Thomas felt that life was not as beautiful as the sunset.
Let's sort out Thomas's work during the day.
From this, we find that Thomas spends a large part of his time on the stylized work of "compiling, packaging, deploying, and testing", while the analysis problems and coding that really need to be implemented by "human" wisdom account for only a small part.
Can you leave these stylized work to the machine to do it automatically? Of course! This is the automated build.
At this point, the meaning of Maven is realized, and it can be executed automatically from the beginning of the build process to the end:
Thank you for reading! This is the end of the article on "what is the construction order of multiple sub-modules in maven". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.