A packaging method based on Maven filter implementation
Patent Information
- Application Number
- CN202011482734.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-15
- Publication Date
- 2025-01-17
- Estimated Expiration
- 2040-12-15
AI Technical Summary
[0002]现有技术中打包一般采用maven的打包命令,指定配置文件目录,生成上线war包,但这种方式只适合项目结构为单一功能的项目,而很多现有的项目结构是依赖不同的依赖包来实现不同功能,用现有技术实现的话,只能通过手动打好各个依赖包,再手动拼装或者增量上线,不打全量war包,如此操作,上线风险大,无法做到规范的版本管理,不能自动化操作
[0018] The beneficial effects of the present invention are: it realizes the flexible configuration of Maven packaging commands for different projects according to packaging needs, realizes automated packaging, and has strong scalability. When there are new packaging requirements, configuration files can be added to implement corresponding packaging requirements; Dependent packages are managed based on version number specifications, and version upgrade dependencies are clear at a glance; and it is suitable for a variety of project structures, regardless of single function or multi-function, and packaging requirements can be achieved according to configuration.
Smart Images

Figure CN112506561B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software technology, and in particular to a packaging method based on Maven's filter implementation. Background Art
[0002] In the prior art, packaging generally uses Maven's packaging command to specify the configuration file directory and generate a war package for online release. However, this method is only suitable for projects with a single function in the project structure. Many existing project structures rely on different dependency packages to implement different functions. If implemented using the prior art, each dependency package can only be manually packaged, and then manually assembled or incrementally released without a full war package. This operation has a high risk of online release, and cannot achieve standardized version management or automated operation. Summary of the invention
[0003] In order to overcome the deficiencies of the prior art, the present invention provides a packaging method based on Maven's filter implementation to solve the above-mentioned technical problems.
[0004] The technical method adopted by the present invention to solve its technical problem is: a packaging method based on Maven filter implementation, and the improvement thereof is: comprising the following steps: S1, adding a filters directory under the root directory of a Java project; S2, adding a directory under the filters directory according to packaging requirements, and adding a configuration file under the directory according to packaging requirements; S3, adding configuration items to the configuration file in the format of key=value, where key is the configuration item and value is the value of the configuration item; S4, adding configuration to the pom file corresponding to the Maven project; S5, configuring a packaging command, and deploying a platform Maven command to pass in a specific value of the directory, where the specific value is the file name of the file specified in the configuration file according to the packaging requirements; S6, triggering a packaging operation to complete packaging.
[0005] In the above method, step S2 comprises the following steps:
[0006] S21. Add the deployment environment directory env and the sub-application package directory subpackage under the filters directory;
[0007] S22. Add configuration files under the deployment environment directory env and the sub-application package directory subpackage. The file names of the configuration files are different.
[0008] In the above method, step S3 includes the following steps:
[0009] S31. Add configuration items to the configuration file in the deployment environment directory env in the format of key=value;
[0010] S32, adding configuration items to the configuration file under the sub-application package directory subpackage in the format of key=value;
[0011] S33. Determine whether the value of the configuration file under the deployment environment directory env overlaps with the value of the configuration file under the sub-application package directory subpackage. If so, add the application name configuration app_name to the configuration file under the sub-application package directory subpackage, where app_name is the application name of each sub-application, and jump to S4. If not, jump directly to S4.
[0012] In the above method, when the key to be configured is determined, the configuration item is directly configured using static configuration; when the key to be configured is uncertain, the configuration item is dynamically configured and passed in through a configuration file or command.
[0013] In the above method, the configuration item log path log_path in the configuration file of the deployment environment directory env is dynamically configured, and is configured as log_path=$(app_name), where log_path is the configuration item key in the configuration file under the deployment environment directory env, and app_name is the configuration item key in the configuration file under the sub-application package directory subpackage.
[0014] In the above method, step S4 includes the following steps:
[0015] S41. Add profile configuration in the pom file corresponding to the Maven project. The profile id value is the file name of each configuration file in the deployment environment directory env.
[0016] S42. Add filter configuration in the pom file corresponding to the Maven project, configure two filters, and the two filter tags specify the deployment environment directory env and the sub-application package directory subpackage. According to the packaging requirements, specify one of the configuration files under the deployment environment directory env and the sub-application package directory subpackage, and dynamically obtain the file name of the configuration file, namely $(env) and $(subpackage).
[0017] In the above method, in step S5, the specific value is the file name of the configuration file specified according to the packaging requirements in the configuration files under the deployment environment directory env and the sub-application package directory subpackage.
[0018] The beneficial effects of the present invention are: it realizes the flexible configuration of Maven packaging commands of different projects according to packaging needs, realizes automatic packaging, has strong scalability, and when there are new packaging requirements, configuration files can be added to realize the corresponding packaging requirements; each dependent package of the project is managed based on the version number specification, and the version upgrade dependency is clear at a glance; and it is suitable for a variety of project structures, whether single function or multi-function, the packaging requirements can be realized according to the configuration. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Attached Figure 1 The present invention is a flowchart of a packaging method based on Maven filter implementation. DETAILED DESCRIPTION
[0020] The present invention is further described below in conjunction with the accompanying drawings and embodiments.
[0021] The following will clearly and completely describe the concept, specific structure and technical effects of the present invention in combination with the embodiments and drawings, so as to fully understand the purpose, characteristics and effects of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, other embodiments obtained by technicians in this field without creative work are all within the scope of protection of the present invention. In addition, all the connection / connection relationships involved in the patent do not refer to the direct connection of components, but refer to the formation of a better connection structure by adding or reducing connection accessories according to the specific implementation situation. The various technical features in the invention can be combined interchangeably without conflicting with each other.
[0022] Reference Figure 1 As shown, a packaging method based on Maven filter implementation of the present invention includes the following steps:
[0023] S1. Add a filters directory to the root directory of the Java project. The filters directory is a directory of the Java project and is used to store configuration files.
[0024] S2. Add directories under the filters directory according to packaging requirements, and add configuration files under the directory according to packaging requirements.
[0025] Specifically, in this embodiment, firstly, a deployment environment directory env and a sub-application package directory subpackage are added under the filters directory; then, configuration files are added under the deployment environment directory env and the sub-application package directory subpackage, and the file names of the configuration files are all different.
[0026] S3. Add configuration items to the configuration file in the format of key=value. This format is the common configuration method of the Java configuration file. The key is the configuration item and the value is the value of the configuration item.
[0027] Specifically, in this embodiment, configuration items are added to the configuration files in the deployment environment directory env in the format of key=value; configuration items are added to the configuration files in the sub-application package directory subpackage in the format of key=value. When the key to be configured is determined, that is, when the value to be configured is known, the configuration item is statically configured and can be directly configured; when the key to be configured is uncertain, it needs to rely on other configuration files or commands to be passed in, and the configuration item is dynamically configured.
[0028] When the value of the configuration file under the deployment environment directory env overlaps with the value of the configuration file under the sub-application package directory subpackage, add the application name configuration app_name to the configuration file under the sub-application package directory subpackage. app_name is the application name of each sub-application. Sub-application refers to the name of different services. Then jump to step S4 and continue the process. Step S4 is to add configuration in the pom file corresponding to the Maven project.
[0029] When the value of the configuration file under the deployment environment directory env does not overlap with the value of the configuration file under the sub-application package directory subpackage, directly jump to step S4 and continue the process. Step S4 is to add configuration in the pom file corresponding to the Maven project.
[0030] In this embodiment, the configuration item log path log_path in the configuration file of the deployment environment directory env is dynamically configured, and is configured as log_path = $(app_name), wherein log_path is the configuration item key in the configuration file under the deployment environment directory env, and app_name is the configuration item key in the configuration file under the sub-application package directory subpackage. Based on this configuration method, packaging for different environments can be achieved, the sub-application name can be dynamically obtained, and different applications can be saved to different log paths.
[0031] S4. Add configuration to the pom file corresponding to the Maven project. The pom file is a fixed configuration file in the Maven project.
[0032] Specifically, in this embodiment, a profile configuration is added to the pom file corresponding to the Maven project. The profile configuration is a tag in the pom file. The pom file is a file in XML format. The profile tag is defined, and the profile id is the file name of each configuration file under the deployment environment directory env. A filter configuration is added to the pom file corresponding to the Maven project. The filter configuration is a tag defined in the pom file in the pom file. Two filters are configured. The two filter tags specify the deployment environment directory env and the sub-application package directory subpackage, that is, the two filters are the deployment environment directory env and the sub-application package directory subpackage. According to the packaging requirements, a configuration file in the configuration files under the deployment environment directory env and the sub-application package directory subpackage is specified, and the file name of the configuration file is dynamically obtained, that is, $(env) and
[0033] $(subpackage) associates the deployment environment directory env and the sub-application package directory subpackage with the Maven project to ensure that the configuration files can be obtained during the packaging process.
[0034] S5. Configure the packaging command and deploy the platform Maven command to pass the specific value of the directory into the Maven command parameter. The specific value is the file name of the file specified in the configuration file according to the packaging requirements.
[0035] In this embodiment, the specific value is the file name of the configuration file specified according to the packaging requirements in the configuration files under the deployment environment directory env and the sub-application package directory subpackage, so as to configure different packaging commands according to different combinations of env and subpackage to realize the packaging requirements of different environments and different services.
[0036] S6. Trigger the packaging operation and complete the packaging.
[0037] The packaging method of the present invention is based on Maven filter implementation, which can flexibly configure Maven packaging commands of different projects according to packaging needs, realize automatic packaging, and has strong scalability. When there is a new packaging requirement, a configuration file can be added to realize the corresponding packaging requirement; each dependent package of the project is managed based on the version number specification, and the version upgrade dependency is clear at a glance; and the method is suitable for a variety of project structures, and packaging requirements can be realized according to the configuration regardless of single function or multi-function.
[0038] The above is a specific description of the preferred implementation of the present invention, but the invention is not limited to the embodiments. Those skilled in the art can make various equivalent modifications or substitutions without violating the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of this application.
Claims
1. A packaging method based on Maven filter implementation, characterized in that: The steps include: S1. Add the filters directory to the root directory of the Java project; S2. Add directories under the filters directory according to packaging requirements, and add configuration files under the directories according to packaging requirements; The step S2 comprises the following steps: S21. Add the deployment environment directory env and the sub-application package directory subpackage under the filters directory; S22. Add configuration files under the deployment environment directory env and the sub-application package directory subpackage. The file names of the configuration files are different. S3. Add configuration items to the configuration file in the format of key=value, where key is the configuration item and value is the value of the configuration item; The step S3 comprises the following steps: S31. Add configuration items to the configuration file in the deployment environment directory env in the format of key=value; S32, adding configuration items to the configuration file under the sub-application package directory subpackage in the format of key=value; S33, determine whether the value of the configuration file under the deployment environment directory env and the value of the configuration file under the sub-application package directory subpackage overlap, if so, add the application name configuration app_name to the configuration file under the sub-application package directory subpackage, where app_name is the application name of each sub-application, and jump to S4; if not, jump directly to S4; When the key to be configured is determined, the configuration item is directly configured using static configuration; when the key to be configured is uncertain, the configuration item is dynamically configured and passed in through a configuration file or command; The configuration item log path log_path in the configuration file of the deployment environment directory env is a dynamic configuration, and is configured as log_path = $(app_name), where log_path is the configuration item key in the configuration file under the deployment environment directory env, and app_name is the configuration item key in the configuration file under the sub-application package directory subpackage; S4. Add configuration to the pom file corresponding to the Maven project; The step S4 comprises the following steps: S41. Add profile configuration in the pom file corresponding to the Maven project. The profile id value is the file name of each configuration file in the deployment environment directory env. S42. Add filter configuration in the pom file corresponding to the Maven project, configure two filters, the two filter tags specify the deployment environment directory env and the sub-application package directory subpackage, specify one of the configuration files under the deployment environment directory env and the sub-application package directory subpackage according to the packaging requirements, and dynamically obtain the file name of the configuration file, namely $(env) and $(subpackage); S5. Configure the packaging command, and deploy the specific value of the Maven command input directory of the platform. The specific value is the file name of the file specified in the configuration file according to the packaging requirements; S6. Trigger the packaging operation and complete the packaging.
2. A packaging method based on Maven filter implementation as claimed in claim 1, characterized in that: In the step S5, the specific value is the file name of the configuration file specified according to the packaging requirements in the configuration files under the deployment environment directory env and the sub-application package directory subpackage.