Java application publishing method and device
Through the automated Java application release method, the problems of cumbersome release process and low degree of automation in the existing technology are solved, and the rapid release and rollback of Java applications are realized, and efficiency and controllability are improved.
Patent Information
- Application Number
- CN202311785660.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-22
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2043-12-22
AI Technical Summary
The release process of Java applications in the existing technology is cumbersome, requiring manual installation of jdk, uploading jar files, executing startup commands, etc., resulting in low automation, cumbersome release of multiple batches of machines, and complex application rollback.
Provides a Java application publishing method, which realizes automated publishing and rollback by creating Java applications, packaging, uploading, setting JVM parameters and file paths, registering environment variables, detecting and installing jdk, closing application processes, creating deployment directories, backing up and starting applications, and detecting application status.
It realizes rapid release and rollback of Java applications, improves release efficiency, reduces error risks, provides a flexible rollback mechanism, and ensures the controllability of application release.
Smart Images

Figure CN117785227B_ABST
Abstract
Description
Technical Field
[0001] This document relates to the field of computer technology, and in particular to a Java application publishing method and device. Background Art
[0002] With the continuous development of information technology, Java applications have been widely used in all walks of life. However, in the development and release process of Java applications, there are some cumbersome and time-consuming steps, which limit the rapid deployment and update of applications. To solve this problem, the present invention proposes a method and device for quickly releasing Java applications.
[0003] Currently, the release process of Java applications usually requires manual installation of JDK, uploading of jar files to the running server, and then logging in to the server to execute the application startup command. If multiple servers need to be released, these steps not only require developers to invest a lot of time, but also easily cause configuration errors and version inconsistencies, thereby affecting the stability and update efficiency of the application.
[0004] In summary, the existing technology has many manual operation steps, low automation, cumbersome and error-prone release of multiple batches of machines, and complex application rollback. Summary of the invention
[0005] The purpose of the present invention is to provide a Java application publishing method and device, aiming to solve the above-mentioned problems in the prior art.
[0006] The present invention provides a Java application publishing method, comprising:
[0007] Create a Java application, package the Java application into a jar package, upload the jar package to the platform, and assign the application jar package name to AppJarName; add the application host to be released, set the JVM parameters during the Java application startup process and assign them to JAVA_OPTS, modify the file path of the Java application uploaded to the application host and assign it to filePath; register the above assigned parameters AppJarName, JAVA_OPTS and filePath as environment variables;
[0008] According to AppId, a synchronization lock is added. In the case of concurrent publishing, a serial execution loop traverses the application host to be published and performs the following operations: detect whether JDK is installed. If not, automatically install the built-in JDK, close the application process according to AppId, create an application deployment directory based on the environment variable according to AppId, back up the jar package, start the Java application, and detect the status of the Java application.
[0009] The present invention provides a Java application publishing device, comprising:
[0010] The setup module is used to create a Java application, package the Java application into a jar package, upload the jar package to the platform, and assign the application jar package name to AppJarName; add the application host to be released, set the JVM parameters during the Java application startup process and assign them to JAVA_OPTS, modify the file path of the Java application uploaded to the application host, and assign it to filePath; register the above-assigned parameters AppJarName, JAVA_OPTS, and filePath as environment variables;
[0011] The publishing module is used to add a synchronization lock according to the AppId. In the case of concurrent publishing, the serial execution loop traverses the application host to be published, and performs the following operations: detect whether the jdk is installed. If not, automatically install the built-in jdk, close the application process according to the AppId, create an application deployment directory based on the environment variable according to the AppId, back up the jar package, start the Java application, and detect the status of the Java application.
[0012] An embodiment of the present invention further provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the above-mentioned Java application publishing method when executed by the processor.
[0013] An embodiment of the present invention further provides a computer-readable storage medium, on which a program for implementing information transmission is stored, and when the program is executed by a processor, the steps of the above-mentioned Java application publishing method are implemented.
[0014] By adopting the embodiment of the present invention, automatic publishing can be achieved, visual interaction is realized, the operation is simple, and application publishing and rollback of multiple machines can be completed quickly. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate one or more embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0016] Figure 1 is a flow chart of a Java application publishing method according to an embodiment of the present invention;
[0017] Figure 2This is a specific flow chart of Java application publishing according to an embodiment of the present invention;
[0018] Figure 3 is a schematic diagram of a Java application startup status detection command according to an embodiment of the present invention;
[0019] Figure 4 is a schematic diagram of a Java application publishing device according to an embodiment of the present invention;
[0020] Figure 5 is a schematic diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0021] In order to enable those skilled in the art to better understand the technical solutions in one or more embodiments of this specification, the following will be combined with the drawings in one or more embodiments of this specification to clearly and completely describe the technical solutions in one or more embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on one or more embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this document.
[0022] Method Embodiment
[0023] According to an embodiment of the present invention, a Java application publishing method is provided. Figure 1 is a flow chart of a Java application publishing method according to an embodiment of the present invention. Figure 1 As shown, the Java application publishing method according to an embodiment of the present invention specifically includes:
[0024] Step S101, create a Java application, package the Java application into a jar package, upload the jar package to the platform, assign the application jar package name to AppJarName; add the application host to be released, set the JVM parameters during the Java application startup process and assign them to JAVA_OPTS, modify the file path of the Java application uploaded to the application host, and assign it to filePath; register the above-assigned parameters AppJarName, JAVA_OPTS and filePath as environment variables;
[0025] Step S102, adding a synchronization lock according to AppId, in the case of concurrent publishing, serially executing a loop to traverse the application host to be published, and performing the following operations: detecting whether JDK is installed, if not installed, automatically installing the built-in JDK, closing the application process according to AppId, creating an application deployment directory based on the environment variables according to AppId, backing up the jar package, starting the Java application, and detecting the status of the Java application.
[0026] Wherein, detecting the status of the Java application specifically includes:
[0027] Get the process ID based on the flag in the command that starts the Java application;
[0028] Set the maximum waiting time, and based on the process ID, poll to check whether the Java application is started within the maximum waiting time. Specifically include:
[0029] Within the maximum waiting time, determine whether the Java application is started based on the startup mark of the jar application log file. If the startup mark exists in the jar application log file, it is determined that the Java application has been started and exit the loop detection. If it is detected that the pid does not exist, it is determined that the Java application has an error in the startup process, exit the loop detection, and set the exit code to 1; otherwise, the loop detection continues until the maximum waiting time is not met.
[0030] In addition, in the embodiment of the present invention, when the Java application fails to be released or has a serious vulnerability, it is rolled back to the previous version of the Java application. Specifically, it includes:
[0031] Stop the Java application, obtain the process ID based on the AppId and the tag when the Java application was started, and execute kill-9pid to kill the process;
[0032] Obtain the Jar package of the previous version of the Java application backed up in the rollback directory, swap the Jar package in the rollback directory with the Jar package in the lib directory, start the Java application, and detect the status of the Java application.
[0033] In summary, the technical solution of the embodiment of the present invention introduces technologies such as automated publishing, automated rollback, and version control, thereby realizing rapid publishing and updating of Java applications. These improvements greatly simplify the publishing process, reduce the risk of errors, and improve the efficiency and stability of publishing.
[0034] The above technical solution of the embodiment of the present invention is described in detail below in conjunction with the accompanying drawings.
[0035] Step 1. Create an application: Fill in the basic information of the application, including the application name, application description, etc., generate a unique identifier for the application, such as UUID, and assign it to the AppId field;
[0036] Step 2: Upload the Jar package: Use the automatic build tool to automatically compile the Java application source code, package it into a Jar package, and upload it to the platform. Assign the application Jar package name to AppJarName;
[0037] Step 3. Select the host to be released: Add the application host to be released, which is usually a Linux server.
[0038] Step 4: Modify the application configuration: Set the JVM parameters during the Java application startup process and assign them to JAVA_OPTS. Modify the file path uploaded to the host by the application and assign it to filePath.
[0039] Step 5: Register environment variables: Register the above assigned parameters as environment variables so that they can be referenced in the subsequent application release process;
[0040] Step 6: Publish the application: Figure 2 As shown, the specific processing includes the following:
[0041] According to AppId plus synchronization lock, in the case of concurrent publishing, serial execution: loop through the hosts to be published in step 3 and perform the following operations:
[0042] 1. Check whether JDK is installed. If not, automatically install the built-in JDK
[0043] 2. Close the application process according to AppId to prevent port occupation and application failure to start
[0044] 3. Create an application deployment directory based on AppId: The directory is as follows: ${filePath} / ${AppId}
[0045] In the default directory, create the following subdirectories:
[0046] bin, logs, lib, rollback
[0047] .zonetmp / logs, .zonetmp / rollback, .zonetmp / bin
[0048] The bin directory stores the application's process ID
[0049] logs stores the application console logs
[0050] lib stores application jar packages
[0051] rollback stores the previously released application jar package
[0052] .zonetmp / logs stores application logs before this release
[0053] .zonetmp / rollback stores the application jar packages before this release
[0054] .zonetmp / bin stores the application process ID before this release
[0055] 4. Backup.
[0056] Clear .zonetmp and move the rollback jar package to .zonetmp / rollback
[0057] Move the logs file to .zonetmp / logs, move the lib jar package to rollback, and move the jar package in step 2 to the lib directory through sftp.
[0058] 5. Start the application. The startup command is as follows:
[0059] java-Dapplication.tag=${AppId}${JAVA_OPTS}-jar${filePath} / ${AppId} / lib / ${AppJarName}
[0060] >${filePath} / ${AppId} / logs / stdout.log
[0061] -Dapplication.tag=${AppId} is a tag in the startup command
[0062] JAVA_OPTS is the dynamic configuration parameter filled in the [Modify JVM Configuration] step
[0063] ${filePath} / ${AppId} / lib / ${AppJarName} is the absolute path of the application jar package uploaded to lib
[0064] ${filePath} / ${AppId} / logs / stdout.log is the application startup output log
[0065] Step 7, status detection: After executing the startup command, it is necessary to dynamically detect whether the application is started. The detection command is as follows: Figure 3 As shown, the detection steps are as follows:
[0066] According to the mark in the startup command, get the process id. The command is as follows:
[0067] pid=$(ps-C java-f--width 1000|grep"$AppId"|grep-v grep|awk'{print$2}')
[0068] Set the maximum waiting time, poll to check whether the application is started, and within the maximum waiting time range, first start the mark "Tomcat started" according to the jar application log file
[0069] Determine whether the application is started. If the keyword exists in the log file, it means that the application has been started and the loop detection is exited. If the pid is detected to be non-existent, it means that the application has an error during the startup process, the loop detection is exited, and the exit code is set to 1. Otherwise, the loop detection is continued until the maximum waiting time is not met to prevent entering an infinite loop.
[0070] Step 8: Roll back the application: If the application fails to be released or has serious vulnerabilities, you need to roll back the previous version of the application. Perform the rollback as follows:
[0071] 1. Stop the application, and get the process id based on the AppId and the mark of the application startup. The command to get the process id is as follows:
[0072] pid=$(ps-C java-f--width 1000|grep"$AppId"|grep-v grep|awk'{print$2}')
[0073] Execute kill-9pid to kill the process
[0074] 2. Get the previous version of the application Jar package. Because the previous application Jar package will be backed up in the rollback directory before each application deployment, swap the jar package in the rollback directory with the jar package in the lib directory, and then execute the application startup and status monitoring process in the above steps.
[0075] Through the technical solution of the embodiment of the present invention, the rapid release of Java applications is achieved, and the specific beneficial effects include:
[0076] Improve release efficiency: Automated release and status monitoring reduce the time and workload of manual operations and improve the release efficiency of Java applications.
[0077] Reduce the risk of errors: The underlying release details are hidden, allowing application publishers to focus only on the business itself.
[0078] Flexible rollback mechanism: The introduction of version control and rollback mechanism enables quick rollback to the previous version when problems occur during the release process, ensuring the controllability of application release.
[0079] Device Example 1
[0080] According to an embodiment of the present invention, a Java application publishing device is provided. Figure 4Schematic diagram of a Java application publishing device according to an embodiment of the present invention. Figure 4 As shown, the Java application publishing device according to the embodiment of the present invention specifically includes:
[0081] The setting module 40 is used to create a Java application, package the Java application into a jar package, upload the jar package to the platform, and assign the application jar package name to AppJarName; add the application host to be released, set the JVM parameters during the Java application startup process and assign them to JAVA_OPTS, modify the file path of the Java application uploaded to the application host, and assign them to filePath; register the above-assigned parameters AppJarName, JAVA_OPTS and filePath as environment variables;
[0082] The publishing module 42 is used to add a synchronization lock according to the AppId, and in the case of concurrent publishing, serially execute a loop to traverse the application host to be published, and perform the following operations: detect whether the jdk is installed, if not installed, automatically install the built-in jdk, close the application process according to the AppId, create an application deployment directory based on the environment variable according to the AppId, back up the jar package, start the Java application, and detect the status of the Java application. Specifically used for:
[0083] Get the process ID based on the flag in the command that starts the Java application;
[0084] Set a maximum waiting time, based on the process ID, and within the maximum waiting time, poll to check whether the Java application is started, specifically including:
[0085] Within the maximum waiting time, determine whether the Java application is started based on the startup mark of the jar application log file. If the startup mark exists in the jar application log file, it is determined that the Java application has been started and exit the loop detection. If it is detected that the pid does not exist, it is determined that the Java application has an error in the startup process, exit the loop detection, and set the exit code to 1; otherwise, the loop detection continues until the maximum waiting time is not met.
[0086] Further including:
[0087] The rollback module is used to roll back to the previous version of the Java application when the Java application fails to be released or has serious vulnerabilities. Specifically, it includes:
[0088] Stop the Java application, obtain the process ID based on the AppId and the tag when the Java application was started, and execute kill-9pid to kill the process;
[0089] Obtain the Jar package of the previous version of the Java application backed up in the rollback directory, swap the Jar package in the rollback directory with the Jar package in the lib directory, start the Java application, and detect the status of the Java application.
[0090] The embodiment of the present invention is a device embodiment corresponding to the above method embodiment. The specific operations of each module can be understood by referring to the description of the method embodiment, which will not be repeated here.
[0091] Device Example 2
[0092] An embodiment of the present invention provides an electronic device, such as Figure 5 As shown, it includes: a memory 50, a processor 52, and a computer program stored in the memory 50 and executable on the processor 52. When the computer program is executed by the processor 52, the steps described in the method embodiment are implemented.
[0093] Device Example 3
[0094] An embodiment of the present invention provides a computer-readable storage medium, on which a program for implementing information transmission is stored. When the program is executed by the processor 52, the steps described in the method embodiment are implemented.
[0095] The computer-readable storage medium in this embodiment includes, but is not limited to, ROM, RAM, magnetic disk or optical disk, etc.
[0096] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A Java application publishing method, characterized in that: include: Create a Java application, package the Java application into a jar package, upload the jar package to the platform, and assign the application jar package name to AppJarName; add the application host to be released, set the JVM parameters during the Java application startup process and assign them to JAVA_OPTS, modify the file path of the Java application uploaded to the application host and assign it to filePath; register the above assigned parameters AppJarName, JAVA_OPTS and filePath as environment variables; According to AppId, a synchronization lock is added. In the case of concurrent publishing, a serial execution loop traverses the application host to be published, and performs the following operations: detect whether JDK is installed. If not, automatically install the built-in JDK, close the application process according to AppId, create an application deployment directory based on the environment variable according to AppId, back up the jar package, start the Java application, and detect the status of the Java application; If the Java application fails to be released or has serious vulnerabilities, roll back to the previous version of the Java application: stop the Java application, obtain the process ID based on the AppId and the mark when the Java application was started, and execute kill-9pid to kill the process; obtain the Jar package of the previous version of the Java application backed up in the rollback directory, swap the jar package in the rollback directory with the jar package in the lib directory, start the Java application, and detect the status of the Java application.
2. The method according to claim 1, characterized in that Detecting the state of the Java application specifically includes: Get the process ID based on the flag in the command that starts the Java application; A maximum waiting time is set, and based on the process ID, polling is performed to check whether the Java application is started within the maximum waiting time.
3. The method according to claim 2, characterized in that Within the maximum waiting time, the polling to check whether the Java application is started specifically includes: Within the maximum waiting time, determine whether the Java application is started based on the startup mark of the jar application log file. If the startup mark exists in the jar application log file, it is determined that the Java application has been started and exit the loop detection. If it is detected that the pid does not exist, it is determined that the Java application has an error in the startup process, exit the loop detection, and set the exit code to 1; otherwise, the loop detection continues until the maximum waiting time is not met.
4. A Java application publishing device, characterized in that: include: The setup module is used to create a Java application, package the Java application into a jar package, upload the jar package to the platform, and assign the application jar package name to AppJarName; add the application host to be released, set the JVM parameters during the Java application startup process and assign them to JAVA_OPTS, modify the file path of the Java application uploaded to the application host, and assign it to filePath; register the above-assigned parameters AppJarName, JAVA_OPTS, and filePath as environment variables; The publishing module is used to add a synchronization lock according to the AppId, and in the case of concurrent publishing, serially execute a loop to traverse the application host to be published, and perform the following operations: detect whether the JDK is installed, and if not installed, automatically install the built-in JDK, close the application process according to the AppId, create an application deployment directory based on the environment variable according to the AppId, back up the jar package, start the Java application, and detect the status of the Java application; The rollback module is used to roll back to the previous version of the Java application when the Java application fails to be released or has serious vulnerabilities. Specifically, it includes: stopping the Java application, obtaining the process ID according to the AppId and the tag when the Java application is started, and executing kill-9pid to kill the process; Obtain the Jar package of the previous version of the Java application backed up in the rollback directory, swap the Jar package in the rollback directory with the Jar package in the lib directory, start the Java application, and detect the status of the Java application.
5. The device according to claim 4, characterized in that The publishing module is specifically used for: Get the process ID based on the flag in the command that starts the Java application; Set a maximum waiting time, based on the process ID, and within the maximum waiting time, poll to check whether the Java application is started, specifically including: Within the maximum waiting time, determine whether the Java application is started based on the startup mark of the jar application log file. If the startup mark exists in the jar application log file, it is determined that the Java application has been started and exit the loop detection. If it is detected that the pid does not exist, it is determined that the Java application has an error in the startup process, exit the loop detection, and set the exit code to 1; otherwise, the loop detection continues until the maximum waiting time is not met.
6. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the Java application publishing method according to any one of claims 1 to 3.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores an implementation program for information transmission, and when the program is executed by a processor, the steps of the Java application publishing method according to any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
Load balancing mvn-based construction publishing rollback technology
CN114546357A