New Java service packaging method

Through the Ceres-Wrapper tool, the existing JSW crash, poor cross-platform compatibility, complex deployment and limited functions are solved, and unified Java service management, cross-platform compatibility and installation-free features are achieved, improving the stability and performance of Java services.

CN119781743APending Publication Date: 2025-04-08SHANGHAI FUDAN KINGSTAR COMPUTER CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311290012.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-08
Publication Date
2025-04-08

AI Technical Summary

Technical Problem

The existing Java Service Wrapper (JSW) has problems such as crash problems, poor cross-platform compatibility, complex deployment, and limited functionality.

Method used

It provides an innovative Java packaging tool called Ceres-Wrapper. Based on the JSW packaging plug-in, it reimplements the wrapper program, provides unified start, stop, restart, query status and daemon functions, optimizes the classpath loading order, and realizes cross-platform compatibility and installation-free features.

Benefits of technology

It solves the crash problem of JSW, improves cross-platform compatibility, simplifies the deployment process, reduces class loading errors and Spring bean loading exceptions, implements daemon and scrolling log functions, and improves performance and stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781743A_ABST
    Figure CN119781743A_ABST
Patent Text Reader

Abstract

The present invention relates to the field of computer technology, and in particular to a novel Java service packaging method, comprising the following steps: S1: packaging Java source code based on a Maven plug-in to generate a ceres-wrapper deployment package; S2: generating a new wrapper program based on the ceres-wrapper deployment package; S3: running the new wrapper program on an operating system that supports a Java environment. The JSW alternative provided by the present invention implements the function of the wrapper through Java, and can easily achieve cross-platform compatibility and installation-free characteristics; optimizes the classpath loading order, reduces the generation of class loading errors and Spring bean loading exceptions; implements a daemon process, and the daemon process can restart the service process after the Java service process hangs; implements rolling logs, and automatically cleans up the logs of the service process when they are too large.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of computer technology, in particular to a novel Java service packaging method. Background Art

[0002] Java Service Wrapper (JSW) can be used to wrap a Java background program into a background service. The existing JSW operation has the following disadvantages:

[0003] 1. The old JSW is implemented in C++. In some scenarios where Java programs call C++ programs (JNI), JSW may cause the service to crash and cannot be automatically recovered;

[0004] 2. The old JSW is implemented in C++. It needs to rely on class libraries when installed in Windows environment, which makes deployment more troublesome;

[0005] 3. The old JSW packages Java services in Windows environment and cannot be directly started in Linux environment (due to line break and dependency issues of the two operating systems), and vice versa, with poor cross-platform compatibility;

[0006] 4. The old JSW loads the dependencies in the lib folder in alphabetical order, which may cause class loading exceptions;

[0007] 5. The old JSW is divided into free version and paid version. Many functions require the purchase of a license to use (for example, the Java project cannot exceed 4G when packaging).

[0008] Therefore, the present invention provides an innovative Java packaging tool named Ceres-Wrapper. The tool is based on the JSW packaging plug-in, re-implements the packaging program, and provides unified start, stop, restart, query status, daemon and other functions for Java programs, which is conducive to standardizing the unified release, deployment and operation and maintenance of Java programs. Ceres-Wrapper can be used as an alternative to JSW. Summary of the invention

[0009] The purpose of the present invention is to solve the defects mentioned in the above background technology by proposing a novel Java service packaging method.

[0010] The technical solution adopted by the present invention is as follows:

[0011] A new Java service packaging method is provided, comprising the following steps:

[0012] S1: Package the Java source code based on the Maven plug-in to generate the ceres-wrapper deployment package;

[0013] S2: Generate a new wrapper program based on the ceres-wrapper deployment package;

[0014] S3: Run the new wrapper program on an operating system that supports the Java environment.

[0015] As a preferred technical solution of the present invention: the packaging process of the Java source code in S1 includes compilation and packaging.

[0016] As a preferred technical solution of the present invention: the packaging is specifically as follows:

[0017] S1.1: Use the appassembler-maven-plugin to convert the Java application into an application with JSW;

[0018] S1.2: Generate classpath and idx files through the spring-boot-maven-plugin plug-in;

[0019] S1.3: Use the maven-dependency-plugin plugin to collect the files generated during the packaging process and put them in the specified folder;

[0020] S1.4: Create a ceres-wrapper deployment package through the maven-assembly-plugin plug-in.

[0021] As a preferred technical solution of the present invention: in S1.2, ceres-wrapper extracts classpath.idx to optimize the classpath order.

[0022] As a preferred technical solution of the present invention: in S1.3, the maven-dependency-plugin plug-in also puts the external dependencies into a folder.

[0023] As a preferred technical solution of the present invention: in S1.4, the maven-assembly-plugin generates a ceres-wrapper deployment package based on a fixed execution order of the plug-ins.

[0024] As a preferred technical solution of the present invention: after the execution of S1.1 and S1.2, corresponding files are generated, ceres-wrapper copies the file directory to a new deployment package, and generates a deployment package with the suffix ceres-wrapper.zip.

[0025] As a preferred technical solution of the present invention: the new wrapper program generated in S2 is implemented by Java.

[0026] As a preferred technical solution of the present invention: the new wrapper program provides start, stop, query and daemon functions.

[0027] As a preferred technical solution of the present invention: the new wrapper program loads the program according to the optimized classpath sequence.

[0028] Compared with the prior art, the novel Java service packaging method provided by the present invention has the following beneficial effects:

[0029] The present invention provides an alternative to JSW, which requires to be completely consistent with the start and stop commands and directory structure of JSW; implements the function of the wrapper through Java, and can easily achieve cross-platform compatibility and installation-free characteristics; optimizes the classpath loading sequence to reduce class loading errors and Spring bean loading exceptions; implements a daemon process, and the daemon process can restart the service process after the Java service process hangs; implements rolling logs, and automatically cleans up the logs of the service process when they are too large. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 The figure is a flow chart of a method according to a preferred embodiment of the present invention. DETAILED DESCRIPTION

[0032] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of this embodiment can be combined with each other. The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0033] Reference Figure 1 The preferred embodiment of the present invention provides a novel Java service packaging method, comprising the following steps:

[0034] S1: Package the Java source code based on the Maven plug-in to generate the ceres-wrapper deployment package;

[0035] S2: Generate a new wrapper program based on the ceres-wrapper deployment package;

[0036] S3: Run the new wrapper program on an operating system that supports the Java environment.

[0037] The packaging process of the Java source code in S1 includes compilation and packaging.

[0038] The packaging is as follows:

[0039] S1.1: Use the appassembler-maven-plugin to convert the Java application into an application with JSW;

[0040] S1.2: Generate classpath and idx files through the spring-boot-maven-plugin plug-in;

[0041] S1.3: Use the maven-dependency-plugin plugin to collect the files generated during the packaging process and put them in the specified folder;

[0042] S1.4: Create a ceres-wrapper deployment package through the maven-assembly-plugin plug-in.

[0043] In S1.2, ceres-wrapper extracts classpath.idx to optimize the classpath order.

[0044] In S1.3, the maven-dependency-plugin plugin also puts external dependencies into a folder.

[0045] In S1.4, the maven-assembly-plugin generates a ceres-wrapper deployment package based on a fixed execution order of the plug-ins.

[0046] After the execution of S1.1 and S1.2 is completed, the corresponding files are generated, and ceres-wrapper copies the file directory to the new deployment package to generate a deployment package with the suffix ceres-wrapper.zip.

[0047] The new wrapper program generated in S2 is implemented in Java.

[0048] The new wrapper program provides start, stop, query and daemon functions.

[0049] The new wrapper program loads the program according to the optimized classpath sequence.

[0050] In this embodiment, the Maven tool is used to generate the ceres-wrapper deployment package from the Java source code, and the following process is performed:

[0051] Compile, from source code to bytecode (.class file);

[0052] Packaging, collecting the files necessary for program operation according to a certain file structure;

[0053] During the packaging process, the Maven plugin can execute many goals in sequence;

[0054] The appassembler-maven-plugin plug-in can package a Java application into an application with JSW, thereby using the functions of JSW.

[0055] The spring-boot-maven-plugin plugin can package a Java application into a Spring Boot-structured jar, which contains a classpath.idx file with an optimized classpath order.

[0056] The maven-dependency-plugin plug-in can collect the files generated during the Maven execution process (program bytecode, dependencies, configuration files, etc.) and put them into the specified folder. In addition, it can also put external dependencies into the folder, such as the packaged wrapper program.

[0057] Finally, the maven-assembly-plugin plugin creates a new deployment package based on the collected folders.

[0058] Therefore, during the Maven execution process, we fix the execution order of the plug-ins and eventually generate the ceres-wrapper deployment package.

[0059] ceres-wrapper depends on the JSW packaging plug-in (appassembler-maven-plugin) and the spring-boot-maven-plugin plug-in. After these two plug-ins are executed and the corresponding files are generated, ceres-wrapper copies some directories to the new deployment package and generates a deployment package with the suffix ceres-wrapper.zip.

[0060] The following are the folders generated by the JSW packaging plug-in:

[0061]

[0062] The following is the directory structure in the jar generated by the spring-boot-maven-plugin plugin. ceres-wrapper extracts the classpath.idx to optimize the classpath order:

[0063]

[0064] The following is the folder structure of the ceres-wrapper deployment package:

[0065]

[0066]

[0067] The new wrapper program is completely re-implemented in Java and can run on all operating systems that support the Java environment. The wrapper program includes functions such as start, stop, restart, query status, and daemon. The following is a detailed description of the implementation of each command:

[0068] start up:

[0069] The startup process includes parsing the wrapper.conf file configuration items, reading the dependencies in the lib directory, splicing and executing java commands, etc.

[0070] The wrapper process starts the service process through Java's ProcessBuilder and redirects the service process log to application.log. After a simple test, the log printing speed is faster than that of native JSW.

[0071] After the service process is started, the daemon process will be started to monitor the status of the service.

[0072] Query status:

[0073] Querying the status means querying whether the process is alive. The wrapper program determines whether the process is alive based on the pid file of the service and the process information returned by the operating system.

[0074] stop:

[0075] The stop command will first stop the daemon process, then stop the service process, and detect whether the process is killed after a period of time after executing the command.

[0076] Daemon:

[0077] The daemon process will start working 60 seconds after the service process is started, and monitor the survival status of the service process every 10 seconds. If the service process hangs, the daemon process will execute the startup command to start the service process again.

[0078] The daemon also periodically cleans and rotates the application.log file.

[0079] Classpath order:

[0080] Incorrect classpath loading order may lead to class loading errors and Spring bean loading exceptions, so it is necessary to specify the classpath order when starting the service process. JSW loads dependencies in the lib folder in alphabetical order. In the startup method of ceres-wrapper, the classpath.idx file in the Spring Boot Jar is read, and the classpath order is specified according to the Spring order to minimize errors in class and Spring bean loading.

[0081] Ceres-wrapper re-implements the wrapper program in Java, directly taking advantage of the platform compatibility and portability brought by the Java language. Ceres-wrapper follows the commands of JSW to implement functions such as start, stop, restart, query status, and daemonize, and its directory structure is exactly the same as that of JSW. In simple terms, ceres-wrapper integrates the conf and lib folders generated by the JSW packaging plug-in into the new ceres-wrapper deployment package, and re-implements the app scripts and wrapper programs in the bin directory in Java, with functions such as start, stop, restart, query status, and daemonize.

[0082] In order to avoid class loading errors and Spring bean loading exceptions, Ceres-Wrapper adopts a special class loading order to solve class loading errors and Spring bean loading exceptions. It also optimizes the log printing speed and reduces the occurrence of loading errors.

[0083] The Ceres-wrapper packaging tool depends on the JSW packaging plug-in and the spring-boot-maven-plugin plug-in, and uses the maven-assembly-plugin plug-in to generate a deployment package.

[0084] Ceres-Wrapper's wrapper is cross-platform and installation-free, and can run on different operating systems, including Windows, Linux, and MacOS, etc. This means that developers can use Ceres-Wrapper to package and deploy their Java applications in different environments without worrying about platform compatibility issues.

[0085] Ceres-wrapper has the same start and stop commands, directory file structure, and configuration files as JSW, with low migration costs and seamless replacement. Ceres-wrapper can also run in different environments, such as copying applications packaged under Windows to Linux and vice versa, to achieve full platform compatibility. In addition, Ceres-wrapper application logs are faster and have better performance than JSW. The classpath dependency loading order is consistent with Spring Boot Jar, reducing class loading errors. Ceres-wrapper also supports daemons, automatically restarts after a service exits abnormally, and can execute custom cleanup scripts before restarting the service.

[0086] It will be apparent to those skilled in the art that the invention is not limited to the details of the exemplary embodiments described above and that the invention can be implemented in other specific forms without departing from the spirit or essential features of the invention. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description, and it is intended that all variations falling within the meaning and scope of the equivalent elements of the claims be included in the invention. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.

[0087] In addition, it should be understood that although the present specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.

Claims

1. A novel Java service packaging method, characterized in that: The steps include: S1: Package the Java source code based on the Maven plug-in to generate the ceres-wrapper deployment package; S2: Generate a new wrapper program based on the ceres-wrapper deployment package; S3: Run the new wrapper program on an operating system that supports the Java environment.

2. The novel Java service packaging method according to claim 1, characterized in that: The packaging process of the Java source code in S1 includes compilation and packaging.

3. The novel Java service packaging method according to claim 2 is characterized in that: The packaging is as follows: S1.1: Use the appassembler-maven-plugin to convert the Java application into an application with JSW; S1.2: Generate classpath and idx files through the spring-boot-maven-plugin plug-in; S1.3: Use the maven-dependency-plugin plugin to collect the files generated during the packaging process and put them in the specified folder; S1.4: Create a ceres-wrapper deployment package through the maven-assembly-plugin plug-in.

4. The novel Java service packaging method according to claim 3 is characterized in that: In S1.2, ceres-wrapper extracts classpath.idx to optimize the classpath order.

5. The novel Java service packaging method according to claim 4 is characterized in that: In S1.3, the maven-dependency-plugin plugin also puts external dependencies into a folder.

6. The novel Java service packaging method according to claim 5 is characterized in that: In S1.4, the maven-assembly-plugin generates a ceres-wrapper deployment package based on a fixed execution order of the plug-ins.

7. The novel Java service packaging method according to claim 6 is characterized in that: After the execution of S1.1 and S1.2 is completed, the corresponding files are generated, and ceres-wrapper copies the file directory to the new deployment package to generate a deployment package with the suffix ceres-wrapper.zip.

8. The novel Java service packaging method according to claim 1, characterized in that: The new wrapper program generated in S2 is implemented in Java.

9. The novel Java service packaging method according to claim 8, characterized in that: The new wrapper program provides start, stop, query and daemon functions.

10. The novel Java service packaging method according to claim 9, characterized in that: The new wrapper program loads the program according to the optimized classpath sequence.