Class Loading Method, Device, Equipment and Storage Medium in Page Compilation Stage
By using linked list hash collection class objects to add class library elements in order during the JSP compilation stage, the compilation failure and operation exceptions caused by out-of-order class path array objects are solved, the page compilation success and the application stable operation and maintenance process are achieved, and the server compatibility is enhanced.
Patent Information
- Application Number
- CN202410324421.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-21
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2044-03-21
AI Technical Summary
During the JSP compilation stage, due to the out-of-order class path array objects, class file search errors, resulting in compilation failure and operation exceptions. The existing technology is difficult to modify WEB application layer files, which affects the flexibility of operation and maintenance work and the compatibility of application servers.
The target application server is parsed through the application layer class loader, and the class library elements are added in order using the linked list hash collection class objects, and the class path target array object is generated to ensure that the class files are loaded in the correct order, and page compilation operations are performed.
Ensure successful page compilation, reduce operation and maintenance workload, enhance operation and maintenance flexibility and application server compatibility, and simplify operation and maintenance processes.
Smart Images

Figure CN118192984B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technologies, and particularly to a class loading method, apparatus, device, and storage medium during the page compilation stage. Background Art
[0002] Generally, there is only one copy of a class file in the directory library of a WEB (general term for the Internet) application and the jar file library, that is, it is stored in one of the two libraries. However, in some scenarios (scenarios where the application is written irregularly), a class may exist both in the directory library of the WEB application and in the jar (a computer file format) file library of the WEB application (there may be more than one jar file), that is, there may be multiple copies of the same class in the WEB application, and the content in each copy of the class file is inconsistent. In this part of the scenarios, during the JSP (Java Server Page, a dynamic web technology standard) compilation stage, the correct order to search for the required class is: the directory library of the WEB application, the jar file library of the WEB application, that is, first search in the directory library of the WEB application, and then search in the jar file library of the WEB application. Through this order, the correct class file required can be found. However, during the JSP compilation stage, the class path set by the application server for it, that is, the class path array object returned by the application layer class loader (actually processed by the ordinary hash set class of the JDK (Java Development Kit, the software development kit for the java language)) is out of order. Therefore, in the above-mentioned part of the scenarios, that is, when there are multiple copies of the same class in the WEB application, and the content in each copy of the class file is inconsistent, in order to ensure that the application server can find the correct class file required during the JSP compilation stage, it is necessary to temporarily comment or delete all the remaining class files, and only keep one correct class file (actually only keep the one that is the most forward in the correct class path order, that is, from the directory library of the WEB application to the jar file library of the WEB application, the class file with the highest priority in this order) to ensure the success of JSP compilation and the normal operation of the application. However, currently, the class files are not searched in the correct search order, resulting in finding the wrong class, and further resulting in the failure of JSP compilation and abnormal operation of JSP. Currently, modifying the files at the WEB application layer makes the application development inflexible and relatively difficult to modify; modifying the files at the WEB application layer is not convenient for the subsequent operation and maintenance of the application server and the WEB application, making the operation and maintenance work very difficult, cumbersome, and redundant. Summary of the Invention
[0003] In view of this, the purpose of the present invention is to provide a class loading method, device, equipment, and storage medium during the page compilation stage, which can determine the class loading order according to the class path target array object, ensure the successful page compilation and the normal and stable operation of the application, reduce the workload of operation and maintenance personnel, simplify the operation and maintenance process, enhance the flexibility of operation and maintenance, and the compatibility of the application server. The specific solutions are as follows:
[0004] In the first aspect, the present invention discloses a class loading method during the page compilation stage, including:
[0005] Determine the application to be deployed, and deploy the application to be deployed that meets the preset deployment requirements to the target application server;
[0006] Use the application layer class loader to parse the target application server to read the target class library, and store the target class library in the corresponding target array object;
[0007] Add all elements in the target array object to the linked list hash set class object in the first preset element addition order to obtain the class path target array object;
[0008] Send the class path target array object to the target application server and perform page compilation operations based on the class path target array object.
[0009] On the other hand, the determination of the application to be deployed and the deployment of the application to be deployed that meets the preset deployment requirements to the target application server includes:
[0010] Determine the application to be deployed and determine the server pages included in the application to be deployed;
[0011] Judge whether there are more than the preset number of class files of the target class corresponding to the server page in the application to be deployed;
[0012] If there are class files with different contents of the target class in the directory class library and jar file class library included in the target class library, it is determined that there are more than the preset number of class files of the target class in the application to be deployed;
[0013] When there are more than the preset number of class files of the target class in the application to be deployed, it is determined that the preset deployment requirements are met, and the application to be deployed is deployed to the target application server.
[0014] On the other hand, the use of the application layer class loader to parse the target application server to read the target class library and store the target class library in the corresponding target array object includes:
[0015] Obtain the pre-created application layer class loader corresponding to the target application server, and use the application layer class loader to scan and read the target class library; wherein, the target class library includes the directory class library and the jar file class library;
[0016] Store the directory class library into a corresponding directory file array object, and store the jar file class library into a corresponding jar file array object;
[0017] Determine the directory file array object and the jar file array object as the target array object.
[0018] On the other hand, the storing the jar file class library into a corresponding jar file array object includes:
[0019] Obtain the element names of all jar file elements in the jar file class library, and calculate the ASCII code corresponding to each element name;
[0020] Sort all the jar file elements based on the ASCII code to obtain the sorted jar file elements;
[0021] Store the sorted jar file elements into the corresponding jar file array object.
[0022] On the other hand, the adding all elements in the target array object to a linked list hash set class object in a first preset element adding order to obtain a class path target array object includes:
[0023] Use the new keyword in the Java language to create the linked list hash set class object of the software development kit; the linked list hash set adds elements in a second preset element adding order when adding elements;
[0024] Use the for loop method in the Java language to traverse the elements in the directory file array object, and add the elements in the directory file array object to the linked list hash set class object in sequence based on the first preset element adding order;
[0025] Use the for loop method in the Java language to traverse the elements in the jar file array object, and add the elements in the jar file array object to the linked list hash set class object in sequence based on the first preset element adding order to obtain a target linked list hash set class object;
[0026] Convert the target linked list hash set class object into the class path target array object.
[0027] On the other hand, after sending the class path target array object to the target application server, the following steps are further included:
[0028] Traverse the elements in the class path target array object, so as to concatenate the elements in the class path target array object with strings, and separate the elements in the class path target array object with a path separator to obtain a class path string;
[0029] Set the class path string to the class path attribute of the server-side program context.
[0030] On the other hand, the page compilation operation based on the class path target array object includes:
[0031] Receive a page access instruction, and obtain the current class path attribute corresponding to the page access instruction to obtain a corresponding current class path string;
[0032] Find a target class file corresponding to the page access instruction based on the current class path string, and perform the page compilation operation based on the target class file to obtain a successfully compiled page.
[0033] In a second aspect, the present invention discloses a class loading device in the page compilation stage, including:
[0034] An application deployment module, configured to determine an application to be deployed, and deploy the application to be deployed that meets the preset deployment requirements to a target application server;
[0035] A target class library storage module, configured to parse the target application server by using an application layer class loader to read a target class library, and store the target class library in a corresponding target array object;
[0036] An element addition module, configured to add all elements in the target array object to a linked list hash set class object in a first preset element addition order to obtain a class path target array object;
[0037] A page compilation module, configured to send the class path target array object to the target application server and perform a page compilation operation based on the class path target array object.
[0038] In a third aspect, the present invention discloses an electronic device, including:
[0039] A memory, configured to store a computer program;
[0040] A processor, configured to execute the computer program to implement the steps of the class loading method in the page compilation stage as disclosed above.
[0041] Fourthly, the present invention discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the class loading method in the page compilation stage as disclosed above.
[0042] It can be seen that the present invention provides a class loading method in the page compilation stage, including: determining the application to be deployed, and deploying the application to be deployed that meets the preset deployment requirements to the target application server; using the application layer class loader to parse the target application server to read the target class library, and storing the target class library in the corresponding target array object; adding all elements in the target array object to the linked list hash set class object in the first preset element addition order to obtain the class path target array object; sending the class path target array object to the target application server and performing page compilation operations based on the class path target array object. Thus, the present invention uses a linked list hash set class object to add all elements in the target array object in order, so that the elements can always maintain the correct order, improve the class loading order processing mechanism in the page compilation stage, the server can determine the class loading order according to the class path target array object, ensure the success of page compilation and the normal and stable operation of the application, reduce the workload of operation and maintenance personnel, simplify the operation and maintenance process, and enhance the flexibility of operation and maintenance and the compatibility of the application server. Description of the Drawings
[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only the embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained according to the provided drawings.
[0044] Figure 1 It is a flowchart of the class loading method in the page compilation stage disclosed by the present invention;
[0045] Figure 2 It is a schematic diagram of the specific class loading method process in the page compilation stage disclosed by the present invention;
[0046] Figure 3 It is a flowchart of the specific class loading method in the page compilation stage disclosed by the present invention;
[0047] Figure 4 It is a schematic diagram of the structure of the class loading device in the page compilation stage provided by the present invention;
[0048] Figure 5 It is a structural diagram of an electronic device provided by the present invention. Detailed Embodiments
[0049] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0050] Currently, at the JSP compilation stage, the class path set by the application server for it, that is, the class path array object returned by the application layer class loader is out of order. Therefore, in some of the above scenarios, the class files are not searched in the correct search order, resulting in incorrect classes being found, and further causing JSP compilation to fail and JSP operation to have exceptions. Modifying the files in the WEB application layer makes application development inflexible and relatively difficult to modify; modifying the files in the WEB application layer is not convenient for the subsequent operation and maintenance of the application server and the WEB application, making the operation and maintenance work very difficult, cumbersome, and redundant. For this reason, the present invention provides a class loading method at the page compilation stage, which can improve the class loading order processing mechanism at the page compilation stage, enabling the server to determine the class loading order according to the class path target array object, ensuring successful page compilation and normal application operation.
[0051] An embodiment of the present invention discloses a class loading method at the page compilation stage. Refer to Figure 1 As shown, the method includes:
[0052] Step S11: Determine the application to be deployed, and deploy the application to be deployed that meets the preset deployment requirements to the target application server.
[0053] In this embodiment, the application to be deployed is determined, and the application to be deployed that meets the preset deployment requirements is deployed to the target application server. Specifically, the application to be deployed is determined, and the server pages included in the application to be deployed are determined; it is judged whether there are more than a preset number of class files of the target class corresponding to the server page in the application to be deployed; if there are class files with different contents of the target class in the directory class library and the jar file class library included in the target class library, it is determined that there are more than a preset number of class files of the target class in the application to be deployed; when there are more than a preset number of class files of the target class in the application to be deployed, it is determined that the preset deployment requirements are met, and the application to be deployed is deployed to the target application server. As Figure 2As shown in the figure, preparatory work is carried out first before deploying the application. The preparatory work is to confirm that the WEB application to be deployed contains JSP pages, and there are multiple copies of a certain class on which the JSP depends in the WEB application, and the content in each class file is inconsistent. After the confirmation is completed, the WEB application to be deployed is deployed to the application server. Among them, the WEB application is generally in the B / S (Browser / Server) mode, which is an application program accessed through a browser. A class is a Java class, which is an abstract data type representing a collection of objects with specific attributes and behaviors.
[0054] Step S12: Use the application layer class loader to parse the target application server to read the target class library and store the target class library in the corresponding target array object.
[0055] In this embodiment, after determining the application to be deployed and deploying the application to be deployed that meets the preset deployment requirements to the target application server, use the application layer class loader to parse the target application server to read the target class library and store the target class library in the corresponding target array object. Specifically, obtain the pre-created application layer class loader corresponding to the target application server, and use the application layer class loader to scan and read the target class library; among them, the target class library includes the directory class library and the jar file class library; store the directory class library in the corresponding directory file array object, and store the jar file class library in the corresponding jar file array object; determine the directory file array object and the jar file array object as the target array object. Among them, storing the jar file class library in the corresponding jar file array object includes: obtaining the element names of all jar file elements in the jar file class library, and calculating the ASCII code corresponding to each element name; sorting all the jar file elements based on the ASCII code to obtain the sorted jar file elements; storing the sorted jar file elements in the corresponding jar file array object. Among them, the jar file is a software package file format, usually used to aggregate a large number of class files, related metadata and resource files into one file for developing Java platform application software or libraries. ASCII code (American Standard Code for Information Interchange) is a computer coding system based on the Latin alphabet, and 128 characters have been defined so far. An application server is a program that exposes business logic to clients through various protocols, used to run WEB applications and maintain the operating environment of their life cycles, and provides a way to access business logic for client application programs to use.
[0056] Step S13: Add all elements in the target array object to the linked list hash set class object in accordance with the first preset element addition order, so as to obtain a class path target array object.
[0057] In this embodiment, after using the application layer class loader to parse the target application server to read the target class library and storing the target class library in the corresponding target array object, all elements in the target array object are added to the linked list hash set class object in accordance with the first preset element addition order, so as to obtain a class path target array object. Specifically, the linked list hash set class object of the software development kit is created by using the new keyword in the Java language; when adding elements, the linked list hash set class adds elements in accordance with the second preset element addition order; the elements in the directory file array object are traversed by using the for loop method in the Java language, and the elements in the directory file array object are sequentially added to the linked list hash set class object based on the first preset element addition order; the elements in the jar file array object are traversed by using the for loop method in the Java language, and the elements in the jar file array object are sequentially added to the linked list hash set class object based on the first preset element addition order, so as to obtain a target linked list hash set class object; the target linked list hash set class object is converted into the class path target array object.
[0058] It can be understood that the target application server obtains the class path array object by calling the getURLs method of WebappClassLoader. The steps of the getURLs method are as follows: First, use the new keyword in the Java language to create an object of the linked list hash set class in the JDK. The linked list hash set class object is not an ordinary hash set class. When adding elements to an ordinary hash set class, the order is disordered (i.e., out of order), while when adding elements to the linked list hash set class, the order is in order (i.e., added in sequence). Then, use a for loop in the Java language to traverse the elements in the directory file array object in WebappClassLoader (i.e., the array object storing the WEB application directory libraries), and call the method of adding elements to the linked list hash set class to add all elements to the linked list hash set class object in sequence; correspondingly, use a for loop in the Java language to traverse the elements in the jar file array object of WebappClassLoader (i.e., the array object storing the WEB application jar file libraries), and add the above elements to the linked list hash set class object in sequence. After all the WEB application library paths are added to the linked list hash set class object, the order of the elements is already the correct order. Then, by calling the array conversion method in the JDK, the type of the target linked list hash set class object is converted to the type of an ordinary array, that is, all elements are placed in an ordinary array object in order to obtain the class path target array object, and the class path target array object is returned to the target application server. At this time, by calling the getURLs method of WebappClassLoader, the obtained class path target array object stores the paths of all the WEB application libraries, and the order of the elements is the correct order. Among them, WebappClassLoader is the application layer class loader created independently by the application server for each application at the beginning of deploying the WEB application, which is used to load classes or resource files. The getURLs method is the method in WebappClassLoader to obtain the class path array object. By merging the WEB application directory libraries, WEB application jar file libraries, and the external libraries configured by the application itself into a set object, converting this set object into an ordinary array object, and then returning this class path array object; this method actually returns a class path array object of the WEB application required libraries for the application server and the WEB application to use. The WEB-INF directory is the standard folder under the WEB application. The WEB application directory library is the WEB-INF / classes directory, which is the standard directory under the WEB-INF directory and contains multiple class files required by the WEB application. The WEB application jar file library is the WEB-INF / lib directory, which is the standard directory under the WEB-INF directory and contains multiple jar files required for the running of the WEB application.
[0059] Step S14: Send the class path target array object to the target application server and perform page compilation operations based on the class path target array object.
[0060] In this embodiment, after adding all elements in the target array object to the linked list hash set class object in the first preset element addition order to obtain the class path target array object, the class path target array object is sent to the target application server and page compilation operations are performed based on the class path target array object. Specifically, a page access instruction is received, and the current class path attribute corresponding to the page access instruction is obtained to obtain the corresponding current class path string; the target class file corresponding to the page access instruction is found based on the current class path string, and the page compilation operation is performed based on the target class file to obtain a successfully compiled page.
[0061] It can be understood that the class path array object is obtained, and the elements (i.e., paths) in the class path array object are traversed in a for loop in the Java language. All elements are combined into a long string by string concatenation with a path separator between elements to obtain the current class path string, and then the current class path string is set to the JSP class path attribute of the Servlet context. After the application is successfully deployed, when accessing the JSP page through a browser, the application server first compiles the JSP page, obtains the previously set current JSP class path string from the current JSP class path attribute of the Servlet context, and controls the application server to find the class files required for the JSP page in the path order of the current JSP class path string, so that the JSP compilation is successful and the application access is successful. Among them, JSP is a dynamic web technology standard that needs to be compiled into a Servlet first and then run, that is, its essence is a Servlet. A Servlet is a server-side program written in Java, with the characteristics of being independent of platforms and protocols. Its main function is to interactively browse and generate data and generate dynamic WEB content. The Servlet context is an object that meets the requirements of the ServletContext interface and is created uniquely for each WEB application after the application server is started, and this object is the Servlet context.
[0062] The present invention traverses all elements in the directory file array object (i.e., the array object storing the WEB application directory class library) and the jar file array object (i.e., the array object storing the WEB application jar file class library) in sequence through the getURLs method of the WEB application layer class loader (i.e., WebappClassLoader), and adds them in order, so that the elements in the set can maintain the correct order, and the elements in the returned array object still maintain the correct order, ensuring the correct order of finding classes during JSP compilation, enabling WEB application developers to develop flexibly; enhancing the compatibility of the application server and ensuring the normal and stable operation of the application program; enhancing the availability of the application server, making the subsequent operation and maintenance work of the application server and WEB application simple and easy, and reducing the workload of operation and maintenance personnel.
[0063] It can be seen that the present invention provides a class loading method in the page compilation stage, including: determining the application to be deployed, and deploying the application to be deployed that meets the preset deployment requirements to the target application server; using the application layer class loader to parse the target application server to read the target class library, and storing the target class library in the corresponding target array object; adding all elements in the target array object to the linked list hash set class object in the first preset element addition order to obtain the class path target array object; sending the class path target array object to the target application server and performing page compilation operations based on the class path target array object. Thus, the present invention adds all elements in the target array object in order by using the linked list hash set class object, so that the elements can always maintain the correct order, improving the class loading order processing mechanism in the page compilation stage. The server can determine the class loading order according to the class path target array object, ensuring the success of page compilation and the normal and stable operation of the application, reducing the workload of operation and maintenance personnel, simplifying the operation and maintenance process, enhancing the flexibility of operation and maintenance and the compatibility of the application server.
[0064] See Figure 3 As shown, the embodiment of the present invention discloses a class loading method in the page compilation stage. Compared with the previous embodiment, this embodiment further explains and optimizes the technical solution.
[0065] Step S21: Determine the application to be deployed, and deploy the application to be deployed that meets the preset deployment requirements to the target application server.
[0066] Step S22: Obtain the pre-created application layer class loader corresponding to the target application server, and use the application layer class loader to scan and read the target class library.
[0067] In this embodiment, as described above Figure 2As shown in the figure, at the very beginning of the WEB application deployment, the target application server will create a corresponding WebappClassLoader for the target application, that is, the application-layer class loader. The WebappClassLoader reads by parsing the target application, scanning the directory libraries and jar file libraries of the target application. Among them, the target libraries include directory libraries and jar file libraries.
[0068] Step S23: Store the directory libraries into the corresponding directory file array object, and store the jar file libraries into the corresponding jar file array object.
[0069] In this embodiment, after using the application-layer class loader to scan and read the target libraries, store the directory libraries into the corresponding directory file array object, store the jar file libraries into the corresponding jar file array object, and determine the directory file array object and the jar file array object as the target array object.
[0070] It can be understood that the two scanned libraries are respectively stored in two array objects of their own classes. The directory library of the WEB application (usually only one, that is, the WEB-INF / classes directory) is stored in the directory file array object through the WebappClassLoader; the jar file libraries of the WEB application (usually there are multiple jar files, that is, there are multiple jar file paths) are stored in the jar file array object through the WebappClassLoader. It should be noted that the elements in the jar file array object storing the jar file libraries of the WEB application have been sorted according to the ASCII code of the jar file name, and the order of the jar file paths in this array is already the correct order. At this time, the WebappClassLoader has read the directory library and jar file libraries of the WEB application into its two array objects respectively, and the order in the jar file array object is already the correct order. The above function is the function set by the WebappClassLoader itself. The jar file libraries of the WEB application are searched in the order of the ASCII code values of the jar file names (for example, sorted in the English alphabet, such as a.jar, b.jar, c.jar, etc.).
[0071] Step S24: Add all the elements in the target array object to the linked list hash set class object in the order of the first preset element addition order to obtain the class path target array object.
[0072] In this embodiment, the application server adds all the class libraries of the WEB application in the correct order by using a linked list hash set class object, converts them into a class path target array object in this order, and finally returns them in the form of an array object.
[0073] Step S25: Send the class path target array object to the target application server and perform a page compilation operation based on the class path target array object.
[0074] In this embodiment, after adding all the elements in the target array object to the linked list hash set class object in the first preset element addition order to obtain a class path target array object, the class path target array object is sent to the target application server and a page compilation operation is performed based on the class path target array object. After sending the class path target array object to the target application server, traverse the elements in the class path target array object, so as to concatenate the elements in the class path target array object with strings, and separate the elements in the class path target array object with a path separator to obtain a class path string; set the class path string to the class path attribute of the server-side program context.
[0075] Generally, a WEB application contains many JSP pages. After the WEB application is deployed to the application server, during the process of accessing the JSP page through a browser, the application server needs to first compile the JSP page into a Servlet (i.e., the JSP compilation stage), and then run this Servlet (i.e., the JSP running stage), that is, the JSP page needs to be compiled first and then run. At the beginning of the deployment of the WEB application, the application server will first create a corresponding WebappClassLoader for it to load the required class files during the application running process. In the JSP compilation stage, since the JSP page depends on many classes, when compiling, the required class files are searched according to the class path set by the application server for it, so that it can be successfully compiled. Among them, to set the class path, by calling the getURLs method of the WebappClassLoader, the returned class path array object is set to the Servlet context.
[0076] For the specific content of the above step S21, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details are not described herein again.
[0077] It can be seen that in the embodiment of the present application, by determining the application to be deployed and deploying the application to be deployed that meets the preset deployment requirements to the target application server; obtaining the pre-created application layer class loader corresponding to the target application server, and using the application layer class loader to scan and read the target class library; storing the directory class library in the corresponding directory file array object, and storing the jar file class library in the corresponding jar file array object; adding all elements in the target array object to the linked list hash set class object in the first preset element addition order to obtain a class path target array object; sending the class path target array object to the target application server and performing a page compilation operation based on the class path target array object, improving the class loading order processing mechanism in the page compilation stage, the server can determine the class loading order according to the class path target array object, ensuring the success of page compilation and the normal and stable operation of the application, reducing the workload of operation and maintenance personnel, simplifying the operation and maintenance process, and enhancing the flexibility of operation and maintenance and the compatibility of the application server.
[0078] See Figure 4 As shown, the embodiment of the present invention also correspondingly discloses a class loading device in the page compilation stage, including:
[0079] An application deployment module 11, configured to determine an application to be deployed and deploy the application to be deployed that meets the preset deployment requirements to a target application server;
[0080] A target class library storage module 12, configured to use an application layer class loader to parse the target application server to read a target class library, and store the target class library in a corresponding target array object;
[0081] An element addition module 13, configured to add all elements in the target array object to a linked list hash set class object in a first preset element addition order to obtain a class path target array object;
[0082] A page compilation module 14, configured to send the class path target array object to the target application server and perform a page compilation operation based on the class path target array object.
[0083] It can be seen that the present invention includes: determining the application to be deployed, and deploying the application to be deployed that meets the preset deployment requirements to the target application server; using the application layer class loader to parse the target application server to read the target class library, and storing the target class library in the corresponding target array object; adding all elements in the target array object to the linked list hash set class object in the first preset element addition order to obtain the class path target array object; sending the class path target array object to the target application server and performing page compilation operations based on the class path target array object. Thus, the present invention uses the linked list hash set class object to add all elements in the target array object in order, so that the elements can always maintain the correct order, improving the class loading order processing mechanism in the page compilation stage. The server can determine the class loading order according to the class path target array object, ensuring the success of page compilation and the normal and stable operation of the application, reducing the workload of operation and maintenance personnel, simplifying the operation and maintenance process, enhancing the flexibility of operation and maintenance, and the compatibility of the application server.
[0084] In some specific embodiments, the application deployment module 11 specifically includes:
[0085] The application determination unit is used to determine the application to be deployed;
[0086] The server page determination unit is used to determine the server pages included in the application to be deployed;
[0087] The class file quantity judgment unit is used to judge whether there are more than the preset quantity of class files of the target class corresponding to the server page in the application to be deployed;
[0088] The class file quantity determination unit is used to determine that there are more than the preset quantity of class files of the target class in the application to be deployed if there are class files with different contents in the directory class library and the jar file class library included in the target class library for the target class;
[0089] The preset deployment requirement satisfaction determination unit is used to determine that the preset deployment requirements are met when there are more than the preset quantity of class files of the target class in the application to be deployed;
[0090] The application deployment unit is used to deploy the application to be deployed to the target application server.
[0091] In some specific embodiments, the target class library storage module 12 specifically includes:
[0092] The application layer class loader acquisition unit is used to acquire the pre-created application layer class loader corresponding to the target application server;
[0093] A target class library loading unit for scanning and reading the target class library by using the application layer class loader; wherein, the target class library includes the directory class library and the jar file class library;
[0094] A target class library storage unit for storing the directory class library into a corresponding directory file array object;
[0095] An element name obtaining unit for obtaining the element names of all jar file elements in the jar file class library;
[0096] An ASCII code calculating unit for calculating the ASCII code corresponding to each of the element names;
[0097] A jar file element sorting unit for sorting all the jar file elements based on the ASCII code to obtain sorted jar file elements;
[0098] A jar file element storage unit for storing the sorted jar file elements into the corresponding jar file array object;
[0099] A target array object determining unit for determining the directory file array object and the jar file array object as the target array object.
[0100] In some specific embodiments, the element adding module 13 specifically includes:
[0101] A linked list hash set class object creating unit for creating the linked list hash set class object of the software development kit by using the new keyword in the Java language; the linked list hash set class adds elements in a second preset element adding order;
[0102] A directory file array object traversing unit for traversing the elements in the directory file array object by using the for loop method in the Java language;
[0103] A directory file array object adding unit for sequentially adding the elements in the directory file array object to the linked list hash set class object based on the first preset element adding order;
[0104] A jar file array object traversing unit for traversing the elements in the jar file array object by using the for loop method in the Java language;
[0105] A jar file array object adding unit for sequentially adding the elements in the jar file array object to the linked list hash set class object based on the first preset element adding order to obtain a target linked list hash set class object;
[0106] A target linked list hash set class object conversion unit for converting the target linked list hash set class object into the class path target array object.
[0107] In some specific embodiments, the page compilation module 14 specifically includes:
[0108] A class path target array object sending unit for sending the class path target array object to the target application server;
[0109] A class path string generating unit for traversing the elements in the class path target array object, so as to concatenate the elements in the class path target array object with strings and separate the elements in the class path target array object using a path separator to obtain a class path string;
[0110] A class path string setting unit for setting the class path string into the class path attribute of the server-side program context;
[0111] An instruction receiving unit for receiving a page access instruction;
[0112] A current class path string obtaining unit for obtaining the current class path attribute corresponding to the page access instruction to obtain a corresponding current class path string;
[0113] A target class file determining unit for finding a target class file corresponding to the page access instruction based on the current class path string;
[0114] A page compilation unit for performing the page compilation operation based on the target class file to obtain a successfully compiled page.
[0115] Furthermore, an embodiment of the present invention also provides an electronic device. Figure 5 It is a structural diagram of an electronic device 20 shown according to an exemplary embodiment, and the content in the figure cannot be considered as any limitation to the scope of use of the present invention.
[0116] Figure 5 It is a structural schematic diagram of an electronic device 20 provided by an embodiment of the present invention. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. Among them, the memory 22 is used to store a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the class loading method in the page compilation stage disclosed in any of the foregoing embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0117] In this embodiment, the power supply 23 is used to provide operating voltages for the various hardware devices on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of the present invention, and no specific limitation is imposed thereon here; the input / output interface 25 is used to obtain external input data or output data to the outside, and the specific interface type thereof can be selected according to specific application requirements, and no specific limitation is imposed here.
[0118] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, a random access memory, a magnetic disk, an optical disk, etc., and the resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be transient storage or permanent storage.
[0119] Among them, the operating system 221 is used to manage and control the various hardware devices and the computer program 222 on the electronic device 20, and it can be Windows Server, Netware, Unix, Linux, etc. The computer program 222 can further include a computer program capable of completing other specific tasks in addition to the computer program capable of implementing the class loading method in the page compilation stage executed by the electronic device 20 disclosed in any of the foregoing embodiments.
[0120] Furthermore, an embodiment of the present invention also discloses a computer-readable storage medium, in which a computer program is stored, and when the computer program is loaded and executed by a processor, the steps of the class loading method in the page compilation stage disclosed in any of the foregoing embodiments are implemented.
[0121] In this specification, the various embodiments are described in a progressive manner. Each embodiment focuses on the differences from other embodiments, and the same or similar parts among the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method part.
[0122] Finally, it should also be noted that in this text, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the said element.
[0123] The above has introduced in detail the class loading method, apparatus, device and storage medium in the page compilation stage provided by the present invention. Specific examples are used in this text to elaborate on the principle and implementation manner of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for those of ordinary skill in the art, according to the idea of the present invention, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present invention.
Claims
1. A class loading method during the page compilation stage, characterized in that, Including: Determine the application to be deployed, and deploy the application to be deployed that meets the preset deployment requirements to the target application server; Use the application layer class loader to parse the target application server to read the target class library, and store the target class library in the corresponding target array object; Add all elements in the target array object to the linked list hash set class object in the order of the first preset element addition to obtain the class path target array object; Send the class path target array object to the target application server and perform page compilation operations based on the class path target array object; The determining the application to be deployed and deploying the application to be deployed that meets the preset deployment requirements to the target application server includes: determining the application to be deployed and determining the server pages included in the application to be deployed; judging whether there are more than the preset number of class files for the target class corresponding to the server page in the application to be deployed; if there are class files with different contents for the target class in the directory class library and the jar file class library included in the target class library, it is determined that there are more than the preset number of class files for the target class in the application to be deployed; when there are more than the preset number of class files for the target class in the application to be deployed, it is determined that the preset deployment requirements are met, and the application to be deployed is deployed to the target application server; The using the application layer class loader to parse the target application server to read the target class library and storing the target class library in the corresponding target array object includes: obtaining the pre-created application layer class loader corresponding to the target application server, and using the application layer class loader to scan and read the target class library; wherein, the target class library includes the directory class library and the jar file class library; storing the directory class library in the corresponding directory file array object, and storing the jar file class library in the corresponding jar file array object; determining the directory file array object and the jar file array object as the target array object; Adding all elements in the target array object to the linked list hash set class object in the first preset element addition order to obtain the class path target array object includes: creating the linked list hash set class object of the software development kit using the new keyword in the Java language; when adding elements to the linked list hash set, adding them in the second preset element addition order; where the second preset element addition order is the order of insertion of elements; traversing the elements in the directory file array object using the for loop method in the Java language, and adding the elements in the directory file array object to the linked list hash set class object in sequence based on the first preset element addition order; traversing the elements in the jar file array object using the for loop method in the Java language, and adding the elements in the jar file array object to the linked list hash set class object in sequence based on the first preset element addition order to obtain the target linked list hash set class object; converting the target linked list hash set class object to the class path target array object; Adding the elements in the jar file array object to the linked list hash set class object in sequence based on the first preset element addition order to obtain the target linked list hash set class object includes: calling the add element method of the linked list hash set class, and adding all elements in the jar file array object to the linked list hash set class object in sequence to obtain the target linked list hash set class object.
2. The class loading method during the page compilation stage according to claim 1, characterized in that, Storing the jar file class library in the corresponding jar file array object includes: Obtaining the element names of all jar file elements in the jar file class library, and calculating the ASCII code corresponding to each element name; Sorting all the jar file elements based on the ASCII code to obtain the sorted jar file elements; Storing the sorted jar file elements in the corresponding jar file array object.
3. The class loading method in the page compilation stage according to any one of claims 1 to 2, characterized in that, After sending the class path target array object to the target application server, it further includes: Traversing the elements in the class path target array object, so as to concatenate the elements in the class path target array object with strings, and separating the elements in the class path target array object using the path separator to obtain the class path string; Setting the class path string to the class path attribute of the server-side program context.
4. The class loading method in the page compilation stage according to claim 3, wherein Performing page compilation operations based on the class path target array object includes: Receiving a page access instruction, and obtaining the current class path attribute corresponding to the page access instruction to obtain the corresponding current class path string; Searching for the target class file corresponding to the page access instruction based on the current class path string, and performing the page compilation operation based on the target class file to obtain a successfully compiled page.
5. A class loading device during the page compilation stage, characterized in that, It includes: An application deployment module for determining the application to be deployed and deploying the application to be deployed that meets the preset deployment requirements to the target application server; A target class storage module, which is used to parse the target application server by using an application-layer class loader to read a target class library and store the target class library into a corresponding target array object; An element addition module, which is used to add all elements in the target array object to a linked list hash set class object in a first preset element addition order to obtain a class path target array object; A page compilation module, which is used to send the class path target array object to the target application server and perform a page compilation operation based on the class path target array object; The application deployment module is specifically used to determine an application to be deployed and determine server pages included in the application to be deployed; and judge whether there are more than a preset number of class files for a target class corresponding to the server page in the application to be deployed; If there are class files with different contents for the target class in a directory class library and a jar file class library included in the target class library, it is determined that there are more than a preset number of the class files for the target class in the application to be deployed; When there are more than a preset number of the class files for the target class in the application to be deployed, it is determined that the preset deployment requirement is met, and the application to be deployed is deployed to the target application server; The target class storage module is specifically used to obtain a pre-created application-layer class loader corresponding to the target application server and use the application-layer class loader to scan and read the target class library; wherein, the target class library includes the directory class library and the jar file class library; store the directory class library into a corresponding directory file array object, and store the jar file class library into a corresponding jar file array object; and determine the directory file array object and the jar file array object as the target array object; The element addition module is specifically used to create the linked list hash set class object of the software development kit by using the new keyword in the Java language; the linked list hash set adds elements in a second preset element addition order; wherein, the second preset element addition order is the order of insertion of elements; use the for loop method in the Java language to traverse the elements in the directory file array object, and sequentially add the elements in the directory file array object to the linked list hash set class object based on the first preset element addition order; use the for loop method in the Java language to traverse the elements in the jar file array object, and sequentially add the elements in the jar file array object to the linked list hash set class object based on the first preset element addition order to obtain a target linked list hash set class object; and convert the target linked list hash set class object into the class path target array object; The device is further used to call the add element method of the linked list hash set class to sequentially add all elements in the jar file array object to the linked list hash set class object to obtain a target linked list hash set class object.
6. An electronic device, characterized in that, It includes: A memory, which is used to store a computer program; A processor for executing the computer program to implement the steps of the class loading method in the page compilation stage as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, For storing a computer program; wherein, when the computer program is executed by a processor, it implements the class loading method in the page compilation stage as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Method and device for realizing application hot deployment
CN110716720A
Static resource loading method and device, equipment and storage medium
CN113568752A