Application program packaging method and device, medium and product
Through layered packaging and ZIP compression technology, the problems of increased deployment time and poor maintainability caused by Spring Boot application packaging are solved, and incremental deployment and efficient deployment package management are achieved.
Patent Information
- Application Number
- CN202411196609.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2024-12-20
AI Technical Summary
Under the Spring Boot framework system, existing application packaging methods lead to an increase in deployment and transmission time, and the incremental deployment cannot be achieved, and the deployment packages are poor maintainability and scalability.
By layering the application's static resources, configuration files, dependency plug-ins and business code, putting them in the /config, /lib and /boot directories respectively, and using ZIP compression technology to package them, incremental deployment is achieved and deployment efficiency is improved and maintainability.
The incremental deployment method is realized, the deployment efficiency is improved, the maintenance and scalability of the deployment package is enhanced, and the problem is easy to troubleshoot and track.
Smart Images

Figure CN119166200A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of application packaging, and in particular to an application packaging method, device, medium and product. Background Art
[0002] Under the Spring Boot framework, the current mainstream technology for application packaging is to package the entire application into a complete Jar package. However, this method has the following problems: on the one hand, the complete Jar package may be relatively large, which increases the deployment and transmission time, and it is impossible to use incremental deployment. On the other hand, the complete Jar package structure is unclear, and static resources, configuration files, and program codes are all put together, resulting in poor maintainability and weak scalability of the application deployment package.
[0003] Based on the above problems, the purpose of the present invention is to provide a lightweight packaging method and device, which can package the application in layers according to different modules, separate the configuration files, static resources, dependent plug-ins and business codes, and place them in different hierarchical directories, so as to realize incremental deployment and improve deployment efficiency. At the same time, the entire deployment package has good maintainability and strong scalability, and is easy to troubleshoot and track problems. Summary of the invention
[0004] The purpose of this application is to provide an application packaging method, device, medium and product to implement an incremental deployment method, improve deployment efficiency, improve the maintainability and scalability of the entire deployment package, and facilitate the troubleshooting and tracking of problems.
[0005] To achieve the above objectives, this application provides the following solutions:
[0006] In a first aspect, the present application provides an application packaging method, comprising:
[0007] Pack the static resources of the application into the / config directory under the application compilation directory to obtain a packaged / config directory;
[0008] Move the application's dependent plug-in Jar files to the / lib directory under the application's compilation directory to obtain a packaged / lib directory;
[0009] Write the relative path information of the dependent plug-in Jar file into the MANIFEST.MF file to obtain the updated MANIFEST.MF file;
[0010] Put all the business codes of the application and the updated MANIFEST.MF file into the / boot directory under the application compilation directory to obtain a packaged / boot directory;
[0011] Using ZIP compression technology, the packaged / config directory, the packaged / lib directory, and the packaged / boot directory are uniformly output to a compressed package according to the original hierarchical relationship to achieve packaging of the application.
[0012] Optionally, the static resources of the application are packaged into the / config directory under the application compilation directory to obtain a packaged / config directory, including:
[0013] Find all static resources from the resources directory and profile directory of the application;
[0014] Determining a current environment activation flag for the application;
[0015] Filtering each of the static resources using the current environment activation identifier;
[0016] All static resources that meet the filtering requirements are copied to the / config directory under the application compilation directory to obtain a packaged / config directory.
[0017] Optionally, determining the current environment activation identifier of the application includes:
[0018] Find the corresponding configuration value according to the app.profile configuration name from the environment variables of the operating system and the application configuration file of the application;
[0019] The current environment activation identifier of the application is determined according to the configuration value.
[0020] Optionally, determining the current environment activation identifier of the application according to the configuration value includes:
[0021] When the configuration value is dev, the current environment activation identifier is determined as the local development environment;
[0022] When the configuration value is test, the current environment activation identifier is determined as a test environment;
[0023] When the configuration value is prod, the current environment activation identifier is determined as the production environment.
[0024] Optionally, before moving the dependent plug-in Jar file of the application to the / lib directory under the application compilation directory to obtain the packaged / lib directory, the method further includes:
[0025] Using Maven project dependency management technology, obtain the dependency tree structure topology diagram of the application, and generate a structured dependency file in the application compilation directory; the structured dependency file includes: all dependency plug-in Jar package information that the application depends on;
[0026] The structured dependency file is parsed in a standardized manner to obtain all dependency plug-in Jar files that the application depends on.
[0027] Optionally, all business codes of the application and the updated MANIFEST.MF file are placed in the / boot directory under the application compilation directory to obtain a packaged / boot directory, including:
[0028] Using the File tool class in the Java language development tool library and the ZIP compression technology, all business codes are obtained from the src directory of the application;
[0029] Compress the class bytecode files compiled from each of the business codes and the updated MANIFEST.MF files into a Jar file;
[0030] Put the Jar file into the / boot directory under the application compilation directory to obtain the packaged / boot directory.
[0031] In a second aspect, the present application provides a computer device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement any of the above-described application packaging methods.
[0032] In a third aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described application packaging methods.
[0033] In a fourth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements any of the above-mentioned application packaging methods.
[0034] According to the specific embodiments provided in this application, this application discloses the following technical effects:
[0035] The present application discloses an application packaging method, device, medium and product, which packages the application in layers according to different modules, separates configuration files, static resources, dependent plug-ins and business codes, and places them in different hierarchical directories, so as to realize incremental deployment and improve deployment efficiency. At the same time, the entire deployment package has good maintainability and strong scalability, and is easy to troubleshoot and track problems. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0037] Figure 1 A schematic diagram of a process flow of an application packaging method provided in an embodiment of the present application;
[0038] Figure 2 Packaging logic diagram for the application;
[0039] Figure 3 A schematic diagram of the steps to implement the application packaging method;
[0040] Figure 4 It is a data format diagram of structured dependency files;
[0041] Figure 5 A schematic diagram of the structure of a computer device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0042] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0043] The purpose of this application is to provide an application packaging method, device, medium and product, which aims to achieve incremental deployment, improve deployment efficiency, improve the maintainability and scalability of the entire deployment package, and facilitate the troubleshooting and tracking of problems.
[0044] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0045] In an exemplary embodiment, Figure 1-Figure 3 As shown, the application packaging method in this embodiment includes:
[0046] Step 1: Package the static resources of the application into the / config directory under the application compilation directory to obtain the packaged / config directory.
[0047] As an optional implementation, step 1 includes:
[0048] Step 11: Find all static resources from the application's resources directory and profile directory.
[0049] Specifically, the File tool class in the Java language development tool library provides the following functions: find files, list all files in a directory, create files, delete files, rename files, read file contents, write file contents, determine whether a file exists, etc. Use the File tool class to find all static resources from the application's resources directory (including all subdirectories) and profile directory (including all subdirectories). Static resources include files in the following formats: files ending with html, javascript, and css suffixes, which are usually static resources rendered by browsers; files ending with yaml, xml, and properties suffixes, which are usually configuration file resources for applications; files ending with sh and bin suffixes, which are usually startup script resources for applications.
[0050] Step 12: Determine the current environment activation flag for the application.
[0051] As an optional implementation, step 12 includes:
[0052] Step 121: Search for corresponding configuration values according to the app.profile configuration name from the operating system environment variables and the application configuration file of the application.
[0053] Step 122: Determine the current environment activation identifier of the application program according to the configuration value.
[0054] As an optional implementation, step 122 includes:
[0055] Step 1221: When the configuration value is dev, the current environment activation identifier is determined as the local development environment.
[0056] Step 1222: When the configuration value is test, the current environment activation flag is determined as the test environment.
[0057] Step 1223: When the configuration value is prod, the current environment activation identifier is determined as the production environment.
[0058] Step 13: Filter each static resource using the current environment activation flag.
[0059] Specifically, the static resources are filtered using the current environment activation flag. For example, in a test environment, the static resources app.yaml and app-test.yaml will be used, while in a production environment, the static resources app.yaml and app-prod.yaml will be used.
[0060] Step 14: Copy all static resources that meet the filtering requirements to the / config directory under the application compilation directory to obtain the packaged / config directory.
[0061] Specifically, the application compilation directory is the / target directory. For example, if the application is located in the E: / hello-app directory, then the storage directory for static resources is E: / hello-app / target / config.
[0062] Step 2: Move the application's dependent plug-in Jar files to the / lib directory under the application compilation directory to obtain the packaged / lib directory.
[0063] As an optional implementation, before step 2, the method further includes:
[0064] Adopt Maven project dependency management technology to obtain the dependency tree structure topology of the application and generate a structured dependency file in the application compilation directory; the structured dependency file includes: all dependent plug-in Jar package information that the application depends on.
[0065] Perform standardized parsing of structured dependency files to obtain all dependent plug-in Jar files that the application depends on.
[0066] Specifically, Maven is an existing mature project management tool, mainly used for Java project construction, dependency management and project management. It provides a simple way to manage the project construction process, the introduction of dependency libraries, and project dependency topology. Using Maven project dependency management technology, you can get the dependency tree structure topology diagram of the entire application. The dependency tree structure topology diagram generates a structured dependency file under the application compilation directory / target. The structured dependency file uses structured data to record all the dependency plug-in Jar package information that the application depends on. The data format is as follows: Figure 4 As shown. It contains 4 lines of data, each of which contains separator prefix information. A, B, C, and D are all Jar packages that the application depends on, and C and D are both indirect dependencies, because B depends on C, and C depends on D. According to this structured dependency file, according to the +-, |+- separators, standard parsing can be performed to obtain all the dependent plug-in Jar files that the application depends on. The specific parsing process of the structured dependency file is as follows:
[0067] (1) Use the File tool class to read each line of data in this file and view the delimiter information at the beginning of each line.
[0068] (2) If the separator at the beginning of each line is: +-, it means that this line represents a direct dependency. Then, the characters after the +- separator are parsed, which are A and B, indicating that A and B are the direct dependency packages of the application.
[0069] (3) If the separator at the beginning of each line is: |, and the space +- is used after the separator, it means that this line represents the direct dependency of the previous line, where the number of spaces is a multiple of two. For example, if it contains two spaces, it means that it is a direct dependency of B, and if it contains four spaces, it means that it is a direct dependency of C, and so on. From the case, the dependency information can be obtained according to the following parsing logic:
[0070] Figure 4 The third line uses two spaces +-, which means that C is a direct dependency of B. Then parse the characters after the | delimiter, and then delete all the +- and space delimiters to get the dependency of C.
[0071] Figure 4 The fourth line uses four spaces +-, which means that D is a direct dependency of C. Then parse the characters after the | delimiter and delete all the +- and space delimiters to get the dependency of D.
[0072] Finally, we can know that C and D are both indirect dependent packages of the application.
[0073] (4) Finally, we can know that A, B, C, and D are all Jar packages that the application depends on, among which C and D are indirect dependencies.
[0074] Step 3: Write the relative path information of the dependent plug-in Jar file into the MANIFEST.MF file to obtain the updated MANIFEST.MF file.
[0075] Specifically, after knowing the name information of all dependent packages, use the File tool class in the Java language development tool library to move these dependent plug-in Jar files to the / lib directory under the application compilation directory. The application compilation directory is the / target directory. For example, if the application is located in the E: / hello-app directory, then the storage directory of the dependent package resources is E: / hello-app / target / lib. At the same time, write the relative path information of these dependent plug-in Jar files into the MANIFEST.MF file: connect the relative path information of all Jar files with comma separators, and then define an attribute named Class-Path in the MANIFEST.MF file, and put the complete path information into this attribute for unified storage management.
[0076] Step 4: Put all the business codes of the application and the updated MANIFEST.MF file into the / boot directory under the application compilation directory to obtain the packaged / boot directory.
[0077] As an optional implementation, step 4 includes:
[0078] Step 41: Use the File tool class in the Java language development tool library and the ZIP compression technology to obtain all business codes from the src directory of the application.
[0079] Step 42: compress the class bytecode files compiled from each business code and the updated MANIFEST.MF file into a Jar file.
[0080] Step 43: Put the Jar file into the / boot directory under the application compilation directory to obtain the packaged / boot directory.
[0081] Specifically, using the File tool class and ZIP compression technology in the Java language development tool library, all business codes are obtained from the src directory of the application, and the class bytecode files compiled from these business codes are uniformly compressed into a Jar file, and the MANIFEST.MF file is compressed into the Jar file at the same time. Finally, such a lightweight Jar file is placed in the / boot directory under the application compilation directory. The application compilation directory is the / target directory. For example, if the application is located in the E: / hello-app directory, then the business code storage directory is E: / hello-app / target / boot. When the java-jar command is used to start this Jar file, the attribute configuration information of the Class-Path name will be read from the MANIFEST.MF file, and the dependent Jar path of this configuration will be added to the classpath, where the classpath is a location list for specifying the Java virtual machine (JVM) to load class files at runtime. The classpath tells the JVM where to find class files and other resource files, so that the application can load class file programs from these dependent Jar files.
[0082] Step 5: Use ZIP compression technology to output the packaged / config directory, packaged / lib directory, and packaged / boot directory to a compressed package according to the original hierarchical relationship to achieve application packaging.
[0083] Specifically, for the packaged / config directory, the packaged / lib directory, and the packaged / boot directory, use the File tool class in the Java language development tool library to read all the files in these directories, and use the ZIP compression technology to output them to a compressed package according to the original hierarchical relationship. The suffix name of the compressed package is zip, and the file name is the name of the application, such as app.zip, which further reduces the size of the deployment package and facilitates fast transmission.
[0084] In an exemplary embodiment, a computer device is provided, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement an application packaging method.
[0085] In an exemplary embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, a method for packaging an application is implemented.
[0086] In an exemplary embodiment, a computer program product is provided, including a computer program, which implements an application packaging method when executed by a processor.
[0087] In an exemplary embodiment, a computer device is provided. The computer device may be a server or a terminal. The internal structure diagram thereof may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an application packaging method is implemented.
[0088] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0089] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0090] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0091] The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. The non-relational database may include a distributed database based on blockchain, etc., but is not limited thereto. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but is not limited thereto.
[0092] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0093] This article uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core ideas of this application. At the same time, for those skilled in the art, according to the ideas of this application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting this application.
Claims
1. A method for packaging an application, characterized in that: The application packaging method comprises: Pack the static resources of the application into the / config directory under the application compilation directory to obtain a packaged / config directory; Move the application's dependent plug-in Jar files to the / lib directory under the application's compilation directory to obtain a packaged / lib directory; Write the relative path information of the dependent plug-in Jar file into the MANIFEST.MF file to obtain the updated MANIFEST.MF file; Put all the business codes of the application and the updated MANIFEST.MF file into the / boot directory under the application compilation directory to obtain a packaged / boot directory; Using ZIP compression technology, the packaged / config directory, the packaged / lib directory, and the packaged / boot directory are uniformly output to a compressed package according to the original hierarchical relationship to achieve packaging of the application.
2. The application packaging method according to claim 1, characterized in that: Package the static resources of the application into the / config directory under the application compilation directory to obtain the packaged / config directory, including: Find all static resources from the resources directory and profile directory of the application; Determining a current environment activation flag for the application; Filtering each of the static resources using the current environment activation identifier; All static resources that meet the filtering requirements are copied to the / config directory under the application compilation directory to obtain a packaged / config directory.
3. The application packaging method according to claim 2, characterized in that: Determine the current environment activation flag of the application, including: Find the corresponding configuration value according to the app.profile configuration name from the environment variables of the operating system and the application configuration file of the application; The current environment activation identifier of the application is determined according to the configuration value.
4. The application packaging method according to claim 1, characterized in that: Determining the current environment activation identifier of the application according to the configuration value includes: When the configuration value is dev, the current environment activation identifier is determined as the local development environment; When the configuration value is test, the current environment activation identifier is determined as a test environment; When the configuration value is prod, the current environment activation identifier is determined as the production environment.
5. The application packaging method according to claim 1, characterized in that: Before moving the dependent plug-in Jar file of the application to the / lib directory under the application compilation directory to obtain the packaged / lib directory, the process further includes: Using Maven project dependency management technology, obtain the dependency tree structure topology diagram of the application, and generate a structured dependency file in the application compilation directory; the structured dependency file includes: all dependency plug-in Jar package information that the application depends on; The structured dependency file is parsed in a standardized manner to obtain all dependency plug-in Jar files that the application depends on.
6. The application packaging method according to claim 1, characterized in that: Put all the business codes of the application and the updated MANIFEST.MF file into the / boot directory under the application compilation directory to obtain the packaged / boot directory, including: Using the File tool class in the Java language development tool library and the ZIP compression technology, all business codes are obtained from the src directory of the application; Compress the class bytecode files compiled from each of the business codes and the updated MANIFEST.MF files into a Jar file; Put the Jar file into the / boot directory under the application compilation directory to obtain the packaged / boot directory.
7. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the application packaging method according to any one of claims 1 to 6.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the application packaging method described in any one of claims 1 to 6 is implemented.
9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the application packaging method described in any one of claims 1 to 6 is implemented.
