CN-122019057-A - TongWeb container adaptation method and system based on Maven plug-in and Profiles
Abstract
The application discloses a TongWeb container adapting method and system based on a Maven plug-in and Profiles. The method comprises the steps of constructing a package TongWeb dependence elimination and addition logic Maven plug-in, integrating the plug-in a parent POM, configuring two Profiles of Tomcat and TongWeb, inheriting the parent POM and declaring service dependence by a child module, activating a target Profile through a-P parameter during construction, triggering the plug-in to automatically eliminate Tomcat dependence and add TongWeb dependence if TongWeb Profile is activated, and executing Maven packaging to generate a corresponding container deployment package. According to the application, automation and standardization of container adaptation are realized, maintenance cost is reduced through centralized configuration and plug-in multiplexing, tomcat/TongWeb seamless switching is supported, and project expansibility, cleanliness and deployment flexibility are improved.
Inventors
- PENG ZHUANG
Assignees
- 中电云计算技术有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260203
Claims (10)
- 1. A Maven plug-in and profile based TongWeb container adaptation method, the method comprising: s1, constructing TongWeb adapted Maven plugins, wherein the plugins encapsulate TongWeb dependence exclusion and addition logic of container adaptation; S2, integrating the TongWeb adapted Maven plug-in a parent POM file, and configuring at least two Maven Profiles, including a default Profile corresponding to the Tomcat container and TongWeb Profile corresponding to the TongWeb container; S3, the project sub-module inherits the parent POM file through a parent tag, and declares service dependence in the sub-module POM; S4, activating a target Profile through a Maven command line parameter-P during construction, and triggering TongWeb to adapt to execution of a Maven plug-in if TongWeb Profile is activated, so as to automatically complete removal of Tomcat related dependency and addition of TongWeb related dependency in business dependency; And S5, executing a Maven packaging flow, and generating a container deployment package corresponding to the target Profile.
- 2. The method according to claim 1, wherein the TongWeb adapting the functions of the Maven plug-in step S1 comprises: (1) The dependence elimination is to detect the spring-boot-starter-web in the business dependence and automatically add < exclusions > tags to eliminate the spring-boot-starter-tomcat built in the tags; (2) The dependence adding comprises automatically adding TongWeb dependence required by a container, including com.tongweb.spring boot tongweb-spring-boot-starter-2.X and com.tongweb tongweb-emmbed; (3) Version management, namely dynamically managing TongWeb dependent versions through Maven Properties or plug-in configuration; (4) And (3) packaging configuration, namely adjusting maven-war-plug in or maven-jar-plug in configuration to adapt to TongWeb deployment.
- 3. The method of claim 2, wherein the plug-in performs dependency exclusion by traversing an item dependency tree lookup ARTIFACTID as a spring-boot-starter-web dependency, calling addExclusion () method to add the exclusion item with groupId as org. When the plugin adds TongWeb Dependency, the version number is obtained from Maven Properties or plugin configuration by creating a Dependency object of com.tangweb springboot: tongweb-spring-boot-starter-2.X and com.tangweb: tongweb-end, and then the Dependency object is added to the item Dependency list.
- 4. The method according to claim 1, wherein the implementation of TongWeb of adapting Maven plug-ins in step S1 comprises: creating Mojo classes inherited from org.apoche.maven.plug in.abstract Mojo, defining an adapt target, acquiring a Maven Project object in an execute () method, executing dependency elimination and addition logic, and receiving plug-in configuration parameters through @ Parameter annotation.
- 5. The method according to claim 1, wherein in step S2, the parent POM declares groupId, artifactId, version and execution configuration of the TongWeb adapted Maven plug-in by < build > < pluginManagement >.
- 6. The method according to claim 1, characterized in that in step S2: The < id > of the default Profile is tomcat or default, and is configured to activate or not execute TongWeb the adaptation plug-in by default; the < id > of TongWeb Profile is tongweb configured to execute the TongWeb adapt Maven plug-in when active, the plug-in binds to process-DEPENDENCIES phases and executes an adapt target.
- 7. The method according to claim 1, wherein in step S3, the sub-module POM only retains service dependency declarations, has no container adaptation related configuration, and automatically acquires plug-in and Profile configuration by inheriting a parent POM; The service dependence is spring-boot-starter-web.
- 8. The method according to claim 1, wherein in step S4, the build command is specifically: constructing a Tomcat version MVN CLEAN PACKAGE-pl submodule name-am [ -P Tomcat ], wherein-P Tomcat is an optional parameter; TongWeb version MVN CLEAN PACKAGE-pl submodule name-am-P tongweb was constructed.
- 9. A Maven plug-in and Profiles based TongWeb container adaptation system, which when run implements the steps of the Maven plug-in and Profiles based TongWeb container adaptation method according to any one of claims 1-8, the system comprising: a plug-in building unit for building TongWeb a adapted Maven plug-in, said plug-in encapsulating TongWeb dependency exclusion and addition logic for container adaptation; The parent POM configuration unit is used for integrating the TongWeb adapted Maven plug-in the parent POM file and configuring at least two Maven Profiles, including default Profiles corresponding to the Tomcat container and TongWeb Profile corresponding to the TongWeb container; The sub-module management unit is used for inheriting the parent POM file through the < parent > tag by the project sub-module and declaring service dependence in the sub-module POM; The construction execution unit is used for activating a target Profile through a Maven command line parameter-P during construction, and triggering TongWeb to adapt to execution of a Maven plug-in if TongWeb Profile is activated, so as to automatically complete removal of Tomcat related dependency and addition of TongWeb related dependency in business dependency; And the packaging generating unit is used for executing a Maven packaging flow and generating a container deployment package corresponding to the target Profile.
- 10. An electronic device is characterized by comprising a memory and a processor; A memory for storing a computer program; A processor for executing the computer program to implement the steps of the Maven plug-in and Profiles based TongWeb container adaptation method as defined in any one of claims 1 to 8.
Description
TongWeb container adaptation method and system based on Maven plug-in and Profiles Technical Field The application relates to the technical field of container adaptation, in particular to a TongWeb container adaptation method, a system, a computer-readable storage medium and electronic equipment based on a Maven plug-in and profile technology in micro-service application deployment. Background In the context of micro-service architecture widespread use, applications often need to be deployed in a variety of operating environments. Spring Boot is taken as a mainstream Java development framework, and the Tomcat container is integrated by default, but in an enterprise-level scenario, there may be a need to be deployed to a specific application server (e.g., tongWeb). In conventional micro-service project engineering, if a TongWeb container needs to be adapted, the following is generally adopted: 1. copying POM files, namely copying original pom.xml files for each submodule (module) to be adapted TongWeb and renaming the original POM-tongweb.xml files; 2. Modification dependence is that in a pore-tangweb.xml file, the original pore.xml is modified, and the modification method specifically comprises the following steps: (1) The spring-boot-starter-tomcat component in the spring-boot-starter-web dependency is excluded. (2) Specific dependencies required for the addition TongWeb are, for example, com.tongweb. Spring boot: tongweb-spring-boot-starter-2.X and com.tongweb: tongweb-emped. 3. POM is specified at build time-when the build (e.g., packaging) is performed, the use of pon-tongWeb. Xml as a configuration file is explicitly specified by the Maven command, e.g., MVN CLEAN PACKAGE-pl moduleName-am-f pon-tongWeb. Xml. The above scheme has significant drawbacks in multi-module/multi-microservice engineering: (1) The management cost is high, when a micro service module which needs to be adapted TongWeb is newly added, the operations of copying, renaming and basic modification are required to be repeatedly executed, and the workload and the repeatability are high; (2) When Maven dependence in a main pon.xml file is changed (such as version upgrading and newly added dependence), the main pon.xml file needs to be manually synchronized into all pon-tangweb.xml files one by one, and the synchronization omission is easily caused due to the fact that the number of the files is large, so that configuration inconsistency is caused, and buried construction or operation risks are caused; (3) Code redundancy, namely, a plurality of POM files with similar functions and independent functions exist in the project, so that the redundancy of the code is increased; (4) The expansibility is poor, the quick and standardized adaptation of a new container or a new version is difficult to support, and the flexibility is insufficient. Disclosure of Invention In order to solve the problems of high management cost, difficult maintenance, easy error, code redundancy, poor expansibility and the like in the prior art, the application provides a novel TongWeb container adaptation method based on Maven plug-ins and Profiles, and the method can automatically and standardized realize the adaptation of micro service projects to TongWeb containers, thereby greatly improving the development and maintenance efficiency. The core of the invention is that standardization and automation of container adaptation are realized through cooperation of a Maven plug-in and a Profile mechanism, and in order to achieve the purposes, the invention adopts the following technical strategies: (1) And (3) performing logic plug-in adaptation, namely extracting dependency exclusion and injection rules required by TongWeb adaptation from POM files of all sub-modules, and packaging the POM files into independent and reusable Maven plug-ins. The plug-in provides standardized adaptation capability in a modularized form, and realizes one-time construction and multi-place multiplexing. (2) Profile-driven switching-non-invasive switching with Maven Profile as adaptation mode. The Profile is activated through the command line parameter-P tongweb, the plug-in is triggered to automatically execute, and seamless and efficient switching between the two deployment modes of Tomcat and TongWeb is realized on the premise that project source codes and POM files do not need to be modified. (3) Centralized configuration management, namely uniformly defining plug-in behaviors and Profile configuration in a parent POM, and realizing TongWeb centralized management of adaptation dependence. When TongWeb version upgrade or adaptation rules are changed, the configuration of a single part of the parent POM is only required to be modified, so that the configuration can be automatically synchronized to all sub-modules through an inheritance mechanism, and maintenance cost and configuration drift risk are obviously reduced. (4) And the dependency conflict automatic analysis, namely the plug-in intel