Jar package importing method, device and equipment and computer readable medium

By detecting and resolving jar package conflicts before software project development, and replacing or excluding conflicting jar packages through version replacement, the problems of high development costs and low efficiency caused by jar package conflicts are solved, and the development efficiency and stability of the project are improved.

CN119201165APending Publication Date: 2024-12-27GREE ELECTRIC APPLIANCE INC OF ZHUHAI +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411236178.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-04
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

During the software project development process, jar package conflicts are often discovered later in the project development stage, resulting in the need to modify the code and dependency libraries on a large scale, increasing development costs and delaying project progress.

Method used

By detecting whether all jar packages in the project have conflicts, and replacing or excluding conflicting jar packages when there is conflict, generating import addresses to avoid conflicts, ensuring that jar package conflicts are resolved before project development.

Benefits of technology

It significantly reduces development time and cost, improves development efficiency, ensures the stability and compatibility of the project-dependent environment, and avoids runtime errors and performance problems caused by dependency conflicts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201165A_ABST
    Figure CN119201165A_ABST
Patent Text Reader

Abstract

The invention relates to a jar package importing method, device and equipment and a computer readable medium, and belongs to the technical field of computers. The method comprises the steps of obtaining a to-be-imported jar package required by a software project; detecting whether a jar packet conflict exists or not based on the jar packet to be imported; if the jar packet conflict does not exist, generating an import address based on the jar packet to be imported; if the jar package conflict exists, judging whether the version of the jar package to be imported needs to be changed or not; if the version needs to be replaced, executing version replacement and returning to judge whether the jar conflict exists or not; if version replacement does not need to be carried out, conflict jar packet prompting is carried out, conflict jar packet exclusion is carried out, and an import address of a jar packet after conflict jar packet exclusion is generated; and executing the jar packet import based on the import address of the jar packet after the conflict jar packet is excluded. The problem that the project modification range is too large due to the fact that jar package conflicts are carried out again during project development is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a jar package importing method, device, equipment and computer-readable medium. Background Art

[0002] When developing a software project, you may encounter various bugs, among which jar package conflicts are difficult to find and solve. In the traditional development process, jar package conflicts are usually discovered in the later stages of project development. At this time, the project has been basically completed, and the code and dependencies involved are already very complex. Solving jar package conflicts usually requires extensive inspection and modification of existing code and dependent libraries, which is a large workload and time-consuming. This late solution to jar package conflicts will not only delay the project progress, but may also introduce new problems and increase the difficulty of development and maintenance.

[0003] The prior art jar package conflict resolution method is mainly to obtain multiple basic jar packages with dependencies, wherein at least one basic jar package conflicts with the target jar package; then decompress the obtained multiple basic jar packages respectively, and synthesize an intermediate jar package according to the decompressed content; modify the path of each basic jar package in the intermediate jar package to obtain a result jar package. This technical solution decompresses multiple basic jar packages into an intermediate jar package so that the basic jar packages therein have different dependency paths. The path of each basic jar package in the intermediate jar package is modified to further distinguish it from the conflicting target jar package to ensure that the two have different paths. When developing an application, since the path and dependency path of the basic jar package have changed, directly referencing the result jar package will not cause a reference error, effectively avoiding jar package conflicts. This solution is to detect and resolve jar package conflicts during the development process, but at this time the project is already under development, the scope of change is too large, and time is wasted, resulting in increased development costs and low development efficiency of the software project. If most of the jar packages encountered in the project are determined before development, a version without jar package conflicts or jar packages that exclude conflicts are selected, and jar package conflicts are resolved before project development, saving development time and cost.

[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0005] The present application provides a jar package import method to solve the technical problem of excessive modification scope caused by jar package conflicts in the development process of the above-mentioned software project. By detecting whether there are jar package conflicts among all jar packages used in the project, and generating import addresses of all jar packages when there are no jar package conflicts, it is detected whether version replacement is required when there are jar package conflicts. If version replacement is required, the version replacement is performed and the import addresses of all jar packages are generated. If version replacement is not required, the conflicting basic jar package is excluded, one conflicting basic jar package is retained, and then the import addresses of all jar packages are generated. This method can resolve jar package conflicts before project development, thereby improving project development efficiency.

[0006] According to one aspect of an embodiment of the present application, the present application provides a jar package importing method, including: obtaining a jar package to be imported required by a software project; detecting whether there is a jar package conflict based on the jar package to be imported; if there is no jar package conflict, generating an import address based on the jar package to be imported; synchronously, if there is a jar package conflict, determining whether the jar package to be imported needs to be replaced with a version; if a version replacement is required, executing the version replacement and returning to determine whether there is a jar conflict; synchronously, if no version replacement is required, prompting for a conflicting jar package and excluding the conflicting jar package, generating an import address of the jar package after the conflicting jar package is excluded; and executing the jar package import based on the import address of the jar package after the conflicting jar package is excluded.

[0007] Optionally, the detection of whether there is a jar package conflict based on the jar package to be imported includes: obtaining the jar package already existing in the current project; reading the metadata information of the jar package to be imported, the metadata information including the name and version number; matching the jar package to be imported with the jar package already existing in the current project based on the name of the jar package to be imported to obtain a jar package with the same name; comparing the version numbers corresponding to the jar packages with the same name, and outputting them as conflicting jar packages if the version numbers are the same.

[0008] Optionally, the execution version replacement includes: obtaining a conflicting jar package and determining the major version corresponding to the conflicting jar package, distinguishing between a main jar package and an ordinary jar package based on the conflicting jar package; replacing the version of the ordinary jar package, determining whether the version of the main jar package needs to be replaced according to user instructions, and obtaining a conflicting basic jar package; searching for the basic jar package of each version of the conflicting basic jar package under the current major version based on a database; determining whether there is a version of the basic jar package without a conflicting jar package, and if so, exporting the versions of all jar packages; synchronously, if not, replacing the jar package to be replaced or prompting that there is no version replacement; exporting the versions of all jar packages.

[0009] Optionally, the conflicting jar package exclusion includes: determining all jar packages included in the conflicting jar package as basic jar packages; searching for jar packages included in each of the basic jar packages as secondary jar packages; searching for identical jar packages in each of the secondary jar packages, retaining one of the identical jar packages and updating the secondary jar package; iteratively performing identical jar package searches based on the updated secondary jar package, and retaining one of the identical jar packages and updating the secondary jar package until no identical jar packages exist in the obtained secondary jar packages.

[0010] Optionally, the jar package import is executed based on the import address of the jar package after the conflicting jar package is excluded, including: setting a corresponding jar package list of the jar package after the conflicting jar package is excluded, the jar package list including name, version and import address; downloading the corresponding jar package to a temporary directory according to the jar package list; moving the corresponding jar package from the temporary directory to the corresponding deployment location according to project requirements and the jar package list.

[0011] Optionally, after executing the jar package import based on the import address of the jar package after the conflicting jar package is excluded, the method also includes: obtaining the jar package required in the project development process and the major version of the jar package required in the project development process; detecting whether there is a conflict between the jar package required in the project development process and the existing jar package; if there is a conflict, traversing the database to see whether there is a version that does not include the conflicting jar package under the major version; if so, replacing the jar package version and returning to the previous step; if not, prompting a jar package conflict and generating an import address of the jar package after the conflicting jar package is excluded; synchronously, if the jar package required in the project development process does not conflict with the existing jar package, generating the import address of the jar package required in the project development process; and executing the jar package import required in the project development process based on the import address.

[0012] Optionally, the traversal of the database also includes jar package analysis before determining whether there is a version that does not include a conflicting jar package under the major version. The jar package analysis includes: obtaining the jar package and all versions of the jar package; analyzing the basic jar package included in the jar package under each version; and storing the jar package under each version and the included basic jar package into the database.

[0013] According to another aspect of an embodiment of the present application, the present application provides a jar package importing device, including: a jar package acquisition module, used to acquire the jar package to be imported required by the software project; a conflict detection module, used to detect whether there is a jar package conflict based on the jar package to be imported; a conflict handling module, used to generate an import address based on the jar package to be imported when there is no jar package conflict, or to determine whether the jar package to be imported needs to be replaced with a version when there is a jar package conflict; a version handling module, used to execute version replacement when version replacement is required and return to determine whether there is a jar conflict, or to prompt for a conflicting jar package and exclude the conflicting jar package when no version replacement is required, and generate an import address of the jar package after the conflicting jar package is excluded; a jar package import module, used to execute jar package import based on the import address of the jar package after the conflicting jar package is excluded.

[0014] According to another aspect of an embodiment of the present application, the present application provides an electronic device, including a memory, a processor, a communication interface and a communication bus, wherein the memory stores a computer program that can be run on the processor, the memory and the processor communicate through the communication bus and the communication interface, and the steps of the above method are implemented when the processor executes the computer program.

[0015] According to another aspect of an embodiment of the present application, the present application also provides a computer-readable medium having a non-volatile program code executable by a processor, and the program code enables the processor to execute the above method.

[0016] The above technical solution provided by the embodiment of the present application has the following advantages compared with the related art:

[0017] By detecting and resolving jar package conflicts before project development, it avoids the need for large-scale modifications when conflicts occur during project development, significantly reducing development time and costs and improving development efficiency. Through conflict detection, version replacement and conflict elimination, the accuracy and efficiency of operations are improved, making the entire process more efficient and reliable. By resolving potential jar package conflicts, it helps to enhance the stability of the project, avoid runtime errors and performance problems caused by dependency conflicts, and improve the overall quality of the project. Through a systematic conflict detection and processing mechanism before software project development, it can effectively solve the conflict problems that may arise when importing multiple jar packages into the project. First, it detects whether the jar package to be imported conflicts with the jar package in the current project, and replaces or eliminates the conflict when a conflict is detected, thereby ensuring the stability and compatibility of the project's dependency environment. Through the automatic management and update mechanism of the jar package version, when a version conflict is detected, it can automatically decide whether the version needs to be replaced according to the conflict situation, and provide the function of searching and exporting related versions, reducing the need for manual intervention and improving the efficiency and accuracy of version management. By processing the conflicting jar packages, a flexible solution strategy is provided. By replacing the version of the conflicting jar packages or eliminating the conflicts, and generating new import addresses, it is possible to adapt to different project requirements and environments, and ensure the normal operation and dependency consistency of the project. Through the iterative search and update of the basic jar packages and the secondary jar packages, it is ensured that no key jar packages will be missed during the conflict elimination process, thereby improving the accuracy of the import address finally generated. During the project development process, the present invention can also detect and resolve conflicts with existing jar packages during the project development process, and update the jar package version when necessary, and also ensure that the dependent library of the project can meet the development requirements, avoiding development obstacles caused by conflicts. Through the functions of setting, downloading and moving the JAR package list to the deployment location, it is ensured that the whole process from import to final deployment is efficient and error-free, which improves work efficiency and reduces errors caused by improper operation. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0020] Figure 1 A schematic diagram of the hardware environment of a jar package import method provided according to an embodiment of the present application;

[0021] Figure 2 A schematic diagram of a jar package import method according to an embodiment of the present application;

[0022] Figure 3 It is a structural block diagram of a jar package importing device provided according to an embodiment of the present application;

[0023] Figure 4 A schematic diagram of an optional electronic device structure provided according to an embodiment of the present application. DETAILED DESCRIPTION

[0024] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0025] In the subsequent description, the suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present application and have no specific meaning. Therefore, "module" and "component" can be used interchangeably.

[0026] In the related art, the jar package conflicts in software project development are mainly detected and resolved in the later stages of project development. At this time, the project has entered the development stage, the project complexity is relatively high, and the modification workload is relatively large, which may delay the project progress and lead to high project development costs.

[0027] Optionally, in the embodiment of the present application, the above method can be applied to Figure 1 In the hardware environment composed of the terminal 101 and the server 103 shown in FIG. Figure 1 As shown, the server 103 is connected to the terminal 101 via a network, and can be used to provide services for the terminal or a client installed on the terminal. A database 105 can be set on the server or independently of the server to provide data storage services for the server 103. The above-mentioned network includes but is not limited to: a wide area network, a metropolitan area network or a local area network, and the terminal 101 includes but is not limited to a PC, a mobile phone, a tablet computer, etc.

[0028] A jar package import method in an embodiment of the present application can be executed by the server 103, or can be executed jointly by the server 103 and the terminal 101.

[0029] In order to solve the problems mentioned in the background technology, according to one aspect of the embodiments of the present application, reference is made to Figure 2 As shown, an embodiment of a jar package import method is provided, including:

[0030] S202: Obtain the jar package to be imported required by the software project.

[0031] It is understandable that a jar package (Java Archive) is a file format used to package multiple Java class files, related metadata and resources. A jar package is essentially a zip file, but it can be directly recognized and used by the Java runtime environment. During the development of a Java project, jar package conflicts are a relatively easy problem. Jar package conflicts mainly occur when Java projects contain libraries (jar files) with the same name but different versions. The types of jar package conflicts include class definition conflicts, resource file overwriting conflicts, and relationship confusion conflicts. Class conflicts mainly occur when different versions of jar packages may contain classes with the same name but different implementations. Resource file overwriting conflicts mainly occur when non-code resources of a jar package are overwritten when they are loaded or accessed. Dependency confusion mainly occurs when the project contains multiple versions of the same jar package with confused dependencies, causing some classes to fail to be loaded or initialized correctly.

[0032] In this embodiment, for example, the jar packages that need to be imported for the software project to be developed include three jar packages to be imported, namely A jar package, B jar package and C jar package. The A jar package contains D jar package, E jar package and F jar package, the Bjar package contains D jar package, H jar package and I jar package, the C jar package contains three jar packages, namely D jar package, J jar package and K jar package, the D jar package contains Q jar package, W jar package and E jar package, and the H jar package contains Q jar package, R jar package and T jar package. Among them, for two jar packages with the same name, for example, D jar package in A jar package and D jar package in B jar package, if the version numbers of D jar package in A jar package and D jar package in B jar package are the same, then there is a conflict between D jar package in A jar package and D jar package in B jar package; if the version numbers of D jar package in A jar package and D jar package in B jar package are different, then there is no conflict between D jar package in A jar package and D jar package in B jar package.

[0033] S204: Detect whether there is a jar package conflict based on the jar package to be imported.

[0034] Specifically, detecting whether there is a jar package conflict based on the jar package to be imported includes:

[0035] Get the existing jar package in the current project;

[0036] Read the metadata information of the jar package to be imported, including the name and version number;

[0037] Based on the name of the jar package to be imported, match the jar package to be imported with the existing jar packages in the current project to obtain the jar packages with the same name;

[0038] Compare the version numbers of the jar packages with the same name. If the version numbers are different, they are output as conflicting jar packages.

[0039] In this embodiment, by comparing the names and version numbers of the existing jar packages in the current project with the jar packages to be imported, jar packages with the same name but different version numbers are identified as potential sources of conflict. This is mainly because the Java class loading mechanism relies on package names and class names to load classes, and jar packages with the same name but different versions may contain incompatible class definitions or resources, resulting in runtime errors. Through the above steps, it can be known that A jar package, B jar package, and C jar package also contain D jar package, for example, the version numbers of D jar package in A jar package, D jar package in B jar package, and D jar package in C jar package are the same, so there is a conflict between D jar package in A jar package, D jar package in B jar package, and D jar package in C jar package. A jar package, B jar package and C jar package all contain Q jar package. Assume that in this embodiment, when B jar package is produced, the Q jar package in B jar package is the same resource, that is, the version numbers of the Q jar packages in B jar package are different. Therefore, the Q jar package in B jar package is not a conflicting jar package. The conflicting jar packages are the Q jar package in A jar package and the Q jar package in C jar package.

[0040] In the above implementation, by identifying jar package conflicts in advance before the development of the software project, runtime errors and defects caused by problems such as version incompatibility or duplicate class definitions can be significantly reduced, which helps to improve the overall quality and stability of the software. This pre-conflict detection mechanism avoids development stagnation or rework caused by conflict problems in the later stage of project development, thereby significantly accelerating the overall development process of the project. By accurately matching the name and version number of the jar package, the accuracy of the jar package conflict detection of the project is ensured, the consistency and compatibility of the jar package version used in the project is improved, and runtime errors caused by version mismatch are reduced. By timely discovering and resolving jar package conflicts, software crashes, functional anomalies and other problems caused by version conflicts can be effectively avoided, thereby significantly improving the stability and reliability of the software. By solving the jar package conflict problem in the early stage of development, the frequent modification and debugging work required for the project due to dependency problems is reduced, which not only saves development time, but also reduces the manpower cost and resource consumption of later maintenance.

[0041] S206. If there is no jar package conflict, an import address is generated based on the jar package to be imported; synchronously, if there is a jar package conflict, it is determined whether the jar package to be imported needs to be replaced.

[0042] Specifically, to generate the import address, first determine the name of the jar package to be imported, determine the version number of the jar package, determine the source of the jar package, open the configuration file of the build tool or IDE used by the project, and add the corresponding dependencies in the configuration file according to the information of the jar package, including the name, version number and group ID of the specified jar package. After saving the configuration file, the newly added dependencies are automatically parsed by the build tool or IDE, and try to download the jar package and all its required dependencies from the configured warehouse, download the jar package to the local warehouse, and automatically add it to the class path of the project. To determine whether a version change is required, first identify the conflicting jar package version, and determine the version of one or more conflicting jar packages that need to be replaced based on the identified conflicting jar package version. If a version change is required, select a version that is compatible with the current project and other dependent libraries. In the project's build tool or IDE configuration file, update the version number of the conflicting jar package. And make sure that the updated version is compatible with other dependencies in the project, then save the configuration file and rebuild the project.

[0043] S208. If version change is required, execute the version change and return to determine whether there is a jar conflict; synchronously, if version change is not required, prompt for conflicting jar packages and eliminate conflicting jar packages, and generate the import address of the jar package after the conflicting jar packages are eliminated.

[0044] Specifically, executing version replacement includes:

[0045] Get the conflicting jar package and determine the major version corresponding to the conflicting jar package, and distinguish the main jar package from the common jar package based on the conflicting jar package;

[0046] Change the version of the common jar package, determine whether the version of the main jar package needs to be changed according to the user's instructions, and obtain the conflicting basic jar package;

[0047] Based on the database, search for the conflicting base jar packages in each version of the current major version;

[0048] Determine whether there is a non-conflicting jar package version in the basic jar package. If so, export the versions of all jar packages. If not, replace the jar package to be replaced or prompt that there is no version replacement.

[0049] Export the versions of all jar packages.

[0050] In this embodiment, when a jar package conflict is detected, the specific information of the conflicting jar package is first determined, including its name, version number and the major version range. The main jar package (such as the core dependency of the project) and the ordinary jar package (non-core dependency or auxiliary library) in the conflicting jar package are distinguished. For ordinary jar packages, the corresponding version is replaced, that is, different versions of jar packages are found under the same major version. For the main jar package, whether to change the version is determined according to user instructions, and the user instructions include, for example, through command line parameters, graphical interface selection or configuration file settings. If replacement is required, find different versions under the same major version; if not, keep the current version. Use the database to find all available versions of the conflicting basic jar package under the current major version. The database should contain detailed information for each version, including whether there is a known conflict with other jar packages. The database of this embodiment uses local cache or remote service. Determine whether there is a version of the non-conflicting jar package. If it exists, select one of the versions. The selected version can be the latest version or the user-specified version, and export the version information of all related jar packages.

[0051] In the above implementation, by detecting and resolving jar package conflicts, the compatibility of the library and framework versions used in the project is ensured, runtime errors or performance issues caused by version incompatibility are reduced, and the stability and reliability of the project are improved. By distinguishing between the main jar package and the ordinary jar package, and deciding whether to replace the version based on the actual situation, it helps to maintain the clarity and rationality of the project dependencies, avoid unnecessary version upgrades or downgrades, and reduce the maintenance burden. By exporting the version information of all jar packages when a conflict-free jar package version is found, it helps developers understand the currently available version combinations and make more informed decisions. By promptly prompting no version change when a conflict-free version cannot be found, the risks that may be caused by blind upgrades or downgrades are avoided.

[0052] Specifically, conflicting jar packages are excluded:

[0053] Determine all jar packages included in the conflicting jar package as the basic jar package;

[0054] Find the jar packages included in each basic jar package as secondary jar packages;

[0055] Find the same jar packages in each secondary jar package, keep one of the same jar packages and update the secondary jar package;

[0056] Based on the updated secondary jar package, iteratively perform the same jar package search, and retain one of the same jar packages and update the secondary jar package until the same jar package does not exist in the obtained secondary jar package.

[0057] In this embodiment, from the conflicting jar package list, all listed jar packages are selected as the basic jar package set. For each basic jar package, a dependency analysis tool is used to find the jar package it depends on, i.e., the secondary jar package. The dependency relationship between each basic jar package and its secondary jar package is recorded. Traverse all secondary jar packages and find the same jar package contained therein (i.e., the jar package with the same name but different versions). For each group of identical secondary jar packages, one of the versions is selected to be retained and the secondary jar package list is updated. If the secondary jar package is excluded, it is ensured that all the basic jar packages that depend on the secondary jar package can find alternative dependencies, or adjust their dependencies accordingly. Since updating the secondary jar package may affect higher-level dependencies, it is necessary to iteratively perform the above steps of finding and retaining the same jar package. In each iteration, based on the updated secondary jar package list, the same jar package is re-searched and processed until the same jar package version no longer exists in all secondary jar packages. According to the secondary jar package list after the final processing, the build configuration file of the project is updated to ensure that all dependencies have been correctly updated and no new conflicts are introduced. For example, in the aforementioned embodiment, the A jar package, the B jar package, and the D jar package in the C jar package conflict, so one of the D jar packages in the A jar package, the B jar package, or the C jar package is retained. For example, the D jar package in the Bjar package is the optimal path, so the D jar package in the A jar package and the D jar package in the C jar package are removed, and only the D jar package in the B jar package is retained, and there is no conflict in the D jar package in the retained B jar package. At the same time, there is a Q jar package in the D jar package in the A jar package, and the D jar package in the B jar package and the H jar package both include the Q jar package, and the D jar package in the C jar package includes the Q jar package, because the B jar package has been guaranteed to have no conflict when it is produced, and the Q jar package in the B jar package belongs to the same resource, so there is no conflict in the Q jar package in the B jar package, then the A jar package and the Q jar package in the C jar package conflict, so it is sufficient to retain the Q jar package in one of the A jar package and the C jar package.

[0058] In the above implementation, by automatically returning and re-judging whether there is a jar package conflict after executing the version change, potential problems can be discovered and solved in time, avoiding project failure or performance degradation caused by unresolved conflicts. Timely version change helps to improve the stability and reliability of the project, ensures the compatibility between the jar package versions used in the project, and reduces runtime errors and performance problems caused by version conflicts. By determining whether to perform a version change decision process when a jar package conflict is found, if a version change is required, the project problems caused by version conflicts are reduced, and the stability of the project is guaranteed. By setting a jar package list after the conflict jar package is excluded, and downloading and moving the jar package according to the jar package list, the automation of jar package management is realized, which not only reduces the complexity of manual operations, but also improves the accuracy and efficiency of processing. In the process of executing the version change, the import address after the conflict jar package is excluded is generated, ensuring that the correct import address can be generated after the conflict is resolved, thereby avoiding potential problems caused by the wrong import address. Using a temporary directory to download the jar package, and moving the jar package to the deployment location after the project requirements are determined, the download and deployment process of the jar package is more orderly, and necessary checks and adjustments can be performed in the temporary directory, avoiding direct operation of files in the production environment. By considering the project requirements and combining the jar package list to move the corresponding jar package to the final deployment location, it ensures that the jar packages actually required in the project are correctly deployed and meet the specific needs of the project. By eliminating conflicting jar packages and replacing versions, conflicts caused by version mismatches are effectively reduced. The generated import address is processed after conflict elimination, reducing potential errors and improving system stability.

[0059] S210, executing jar package import based on the import address of the jar package after the conflicting jar package is eliminated.

[0060] Specifically, executing the jar package import based on the import address of the jar package after the conflicting jar package is excluded includes:

[0061] Set the corresponding jar package list of the jar package after the conflicting jar package is excluded. The jar package list includes the name, version and import address;

[0062] Download the corresponding jar package to a temporary directory according to the jar package list;

[0063] According to the project requirements and the jar package list, move the corresponding jar package from the temporary directory to the corresponding deployment location.

[0064] In this embodiment, if version change is required, the conflicting jar packages that need to be excluded and the jar packages that need to be upgraded or downgraded are determined according to the version change strategy. Create a new jar package list, including the names, target versions and expected import addresses of these jar packages, and the import address is set to the local path or remote URL; traverse the jar package list, and use the HTTP client to download each jar package from the remote warehouse or local warehouse to the specified temporary directory. According to project requirements, move the jar packages in the temporary directory to the deployment location of the project, including updating the project's classpath settings and modifying the build configuration file; rescan the jar packages in the project to ensure that no new conflicts are introduced after the version change.

[0065] In the above implementation, by setting the jar package list after the conflicting jar packages are excluded, including the name, version and import address, accurate control of project dependencies is achieved, which helps to ensure that only necessary and conflict-free jar packages are included in the project, avoiding potential problems caused by redundant or conflicting dependencies. According to the jar package list, the corresponding jar package is automatically downloaded to the temporary directory, and then moved to the deployment location, which significantly improves the import efficiency of the jar package. By excluding the conflicting jar packages and strictly controlling the version and source of the jar package during the import process, the stability of the project is enhanced, which helps to reduce build failures and operation anomalies caused by version conflicts or dependency errors, and improves the reliability and maintainability of the project. Using a temporary directory as a transfer station for jar packages helps to optimize resource utilization. During the download and deployment process, the temporary directory can cache the downloaded jar packages to avoid repeated downloads and waste of network resources. The temporary directory can also be used as a temporary storage area to facilitate the processing and management of temporary files during the deployment process.

[0066] Specifically, after the jar package is imported based on the import address of the jar package after the conflicting jar package is excluded, the following steps are also included:

[0067] Get the jar packages needed in the project development process and the major versions of the jar packages needed for the project development process summary;

[0068] Check whether there is a conflict between the jar package required during project development and the existing jar package;

[0069] If there is a conflict, the database is traversed to see if there is a version that does not include the conflicting jar package under the major version. If so, the jar package version is replaced and the previous step is returned. If not, a jar package conflict is prompted and the import address of the jar package after the conflicting jar package is excluded is generated;

[0070] Synchronously, if the jar package required during the project development process does not conflict with the existing jar package, the import address of the jar package required during the project development process is generated;

[0071] Import the jar packages required during project development based on the import address.

[0072] In this embodiment, all jar packages and their major version requirements required in the project development process are first determined. Arrange the list of jar packages currently included in the project, including name, version, and import address, etc. Traverse the jar packages in the project requirements and the existing jar package list, compare the name and version, and if a jar package with the same name but different version is found, it is determined to be a conflicting jar package. For the detected conflicting jar package, perform a database traversal operation. Under the major version requirements, find out whether there is a version that does not include the conflicting jar package. If there is a qualified version, select the version as a replacement, and update the jar package list and import address in the project. If there is no qualified version, a conflict report is generated, prompting the jar package conflict, and a new jar package import address list is generated based on the result after the conflict is eliminated. Generate the list of jar packages that need to be imported and their import addresses. Automatically download the jar package to the specified directory according to the import address list. Move the downloaded jar package to the deployment location of the project, and update the project's classpath (class path) and build configuration files.

[0073] In the above implementation, by detecting whether there is a conflict between the jar package required in the project development process and the existing jar package, the compatibility of the project is significantly enhanced, ensuring that in the new project or project update process, there will be no build failure or runtime error due to the jar package conflict. When a conflict is detected, the version that does not contain the conflicting jar package is found and replaced from the database, or the import address after conflict elimination is generated when the alternative version cannot be found. This mechanism reduces the need for manual intervention and improves the development efficiency of the software project. By considering the large version jar package required in the project development process, a higher level of version management is provided, allowing developers to consider the jar package version that may be needed in the future during the project planning stage, thereby reducing problems caused by version mismatches. According to the results of the conflict detection, the jar package import address in different situations can be flexibly generated, including the import address after conflict resolution and the import address after conflict elimination, ensuring that no matter what state the software project is in, a suitable jar package import method can be found. By reducing the build failure and debugging time caused by jar package conflicts, the efficiency of software development is significantly improved.

[0074] Specifically, before traversing the database to see if there is a version that does not include the conflicting jar package under the major version, jar package analysis is also included. The jar package analysis includes:

[0075] Get the jar package and all versions of the jar package;

[0076] Parse the basic jar package included in each version of the jar package;

[0077] Store the jar package of each version and the included basic jar package in the database.

[0078] In this embodiment, the format of the database is first set. The database includes three tables, namely, a jar_packages table for storing basic information of jar packages, a jar_versions table for storing version information of jar packages, and a dependencies table for storing dependencies between jar packages (basic jar package information). Then determine the source of the jar package, including local file system, Maven warehouse, remote server, etc. For each jar package, retrieve all available versions from the specified source according to the corresponding identifier. Download each version of the jar package to the local according to the download link in the jar_versions table. Use the Java library to open the jar package file, and traverse the files and directories to find the basic jar package information, and identify the basic jar package by parsing the class path attribute of the jar package. The basic jar package information of each version of the jar package is stored in the dependencies table, and associated with the corresponding jar_versions record.

[0079] In the above implementation, by parsing the jar package and all its versions, and recording the basic jar package contained in each version, the dependency relationship of each version can be accurately grasped, which helps to quickly locate and solve the compilation or runtime errors caused by dependency conflicts during the project development process, and improve the stability and maintainability of the project. By storing the jar package and its dependency information in the database, it is possible to easily traverse and compare the differences between different versions of the jar package and identify potential version conflicts. By parsing and storing the dependency information of the jar package, it is possible to avoid repeated downloading and storing of the same jar package version, saving storage space and bandwidth resources. At the same time, for the old version of the jar package that has been determined to be no longer used, it can also be cleaned and optimized to maintain efficient use of resources. Through version control, the change history of the jar package dependency can be tracked, providing strong support for the long-term maintenance of the project. Through the jar package database, when the project encounters problems caused by jar package dependency conflicts, relevant dependency information can be quickly provided to help developers quickly locate the cause of the problem. In addition, by comparing the dependency differences between different versions, developers can also try to fall back to a stable version to quickly solve the current problem and reduce project interruption time.

[0080] In all the above-mentioned implementation modes of the present invention, by selecting all the jar packages used in the project, and then detecting whether there are jar package conflicts in all the jar packages used in the selected project, when there are no jar package conflicts, the import addresses of all the jar packages are generated, and when there are jar package conflicts, it is further detected whether version replacement is required, if version replacement is required, the version replacement is performed, and then the import addresses of all the jar packages are generated, if version replacement is not required, the conflicting basic jar packages in one or more jar packages are excluded, one conflicting basic jar package is retained, and then the import addresses of all the jar packages are generated, so that the jar package conflicts can be resolved before project development, thereby improving the efficiency of project development.

[0081] According to another aspect of the embodiment of the present application, Figure 3 As shown, a jar package importing device is provided, comprising:

[0082] The jar package acquisition module 301 is used to acquire the jar package to be imported required by the software project;

[0083] The conflict detection module 303 is used to detect whether there is a jar package conflict based on the jar package to be imported;

[0084] The conflict handling module 305 is used to generate an import address based on the jar package to be imported when there is no jar package conflict, or to determine whether the jar package to be imported needs to be replaced when there is a jar package conflict;

[0085] The version processing module 307 is used to perform version replacement when version replacement is required and return to determine whether there is a jar conflict, or to prompt and exclude conflicting jar packages when version replacement is not required, and generate an import address of the jar package after the conflicting jar package is excluded;

[0086] The jar package importing module 309 is used to perform jar package importing based on the import address of the jar package after the conflicting jar packages are eliminated.

[0087] It should be noted that the jar package acquisition module 301 in this embodiment can be used to execute step S202 in the embodiment of the present application, the conflict detection module 303 in this embodiment can be used to execute step S204 in the embodiment of the present application, the conflict handling module 305 in this embodiment can be used to execute step S206 in the embodiment of the present application, the version processing module 307 in this embodiment can be used to execute step S208 in the embodiment of the present application, and the jar package import module 309 in this embodiment can be used to execute step S210 in the embodiment of the present application.

[0088] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware.

[0089] According to another aspect of the embodiments of the present application, the present application provides an electronic device, such as Figure 4 As shown, it includes a memory 401, a processor 403, a communication interface 405 and a communication bus 407. The memory 401 stores a computer program that can be run on the processor 403. The memory 401 and the processor 403 communicate through the communication interface 405 and the communication bus 407. When the processor 403 executes the computer program, the steps of the above method are implemented.

[0090] The memory and processor in the above electronic device communicate through the communication bus and the communication interface. The communication bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus can be divided into an address bus, a data bus, a control bus, etc.

[0091] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0092] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0093] According to another aspect of the embodiments of the present application, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps of any of the above embodiments.

[0094] Optionally, in an embodiment of the present application, the computer-readable medium is configured to store program codes for the processor to execute the following steps:

[0095] S202, obtaining the jar package to be imported required by the software project;

[0096] S204, detecting whether there is a jar package conflict based on the jar package to be imported;

[0097] S206. If there is no jar package conflict, generate an import address based on the jar package to be imported; synchronously, if there is a jar package conflict, determine whether the jar package to be imported needs to be replaced;

[0098] S208. If version change is required, execute version change and return to determine whether there is a jar conflict; synchronously, if version change is not required, prompt conflicting jar packages and eliminate conflicting jar packages, and generate an import address of the jar package after the conflicting jar packages are eliminated;

[0099] S210, executing jar package import based on the import address of the jar package after the conflicting jar package is eliminated.

[0100] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.

[0101] When the embodiments of the present application are specifically implemented, reference may be made to the above-mentioned embodiments, which have corresponding technical effects.

[0102] It is understood that the embodiments described herein may be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit may be implemented in one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), general purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions of the present application, or a combination thereof.

[0103] For software implementation, the technology of this article can be implemented by a unit that performs the functions of this article. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.

[0104] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0105] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0106] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0107] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0108] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0109] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk. It should be noted that, in this article, 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 that there is any such actual relationship or order between these entities or operations. Moreover, the term "include", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such a process, method, article or device. Without more constraints, an element defined by the phrase "comprising a ..." does not exclude the existence of other identical elements in the process, method, article or apparatus comprising the element.

[0110] The above is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.

Claims

1. A jar package import method, characterized in that: include: Get the jar package to be imported required by the software project; Detecting whether there is a jar package conflict based on the jar package to be imported; If there is no jar package conflict, an import address is generated based on the jar package to be imported; Synchronously, if there is a jar package conflict, determine whether the jar package to be imported needs to be replaced; If a version change is required, execute the version change and return to determine whether there is a jar conflict; Synchronously, if version change is not required, a conflicting jar package prompt is given and the conflicting jar package is eliminated, and an import address of the jar package after the conflicting jar package is eliminated is generated; The jar package import is executed based on the import address of the jar package after the conflicting jar package is eliminated.

2. The jar package import method according to claim 1, characterized in that: The detecting whether there is a jar package conflict based on the jar package to be imported includes: Get the existing jar package in the current project; Read the metadata information of the jar package to be imported, the metadata information includes the name and version number; Based on the name of the jar package to be imported, the jar package to be imported is matched with the existing jar packages in the current project to obtain jar packages with the same name; Compare the version numbers corresponding to the jar packages with the same name, and output them as conflicting jar packages if the version numbers are the same.

3. The jar package import method according to claim 1, characterized in that: The execution version replacement includes: Obtain the conflicting jar package and determine the major version corresponding to the conflicting jar package, and distinguish the main jar package from the common jar package based on the conflicting jar package; Replace the version of the common jar package, determine whether the version of the main jar package needs to be replaced according to the user's instructions, and obtain the conflicting basic jar package; Searching for the base jar package of each version of the conflicting base jar package under the current major version based on the database; Determine whether there is a version of the basic jar package without conflict, and if so, export the versions of all jar packages; synchronously, if not, replace the jar package to be replaced or prompt that there is no version replacement; Export the versions of all jar packages.

4. The jar package import method according to claim 1, characterized in that: The conflicting jar packages excluded include: Determine all jar packages included in the conflicting jar package as basic jar packages; Searching for the jar packages included in each of the basic jar packages as secondary jar packages; Searching for identical jar packages in the secondary jar packages, retaining one of the identical jar packages and updating the secondary jar package; Based on the updated secondary jar package, iteratively perform the same jar package search, and retain one of the same jar packages and update the secondary jar package until the obtained secondary jar package does not contain the same jar package.

5. The jar package importing method according to claim 1, characterized in that: The step of importing the jar package based on the import address of the jar package after the conflicting jar package is excluded includes: Set the corresponding jar package list of the jar package after the conflicting jar package is excluded, and the jar package list includes the name, version and import address; Download the corresponding jar package to a temporary directory according to the jar package list; According to the project requirements and the jar package list, the corresponding jar package is moved from the temporary directory to the corresponding deployment location.

6. The jar package import method according to claim 1, characterized in that: After the jar package import address based on the jar package after the conflicting jar package is excluded is executed, the method further includes: Obtain the jar packages required in the project development process and the major versions of the jar packages required for the project development process summary; Check whether there is a conflict between the jar package required during the project development and the existing jar package; If there is a conflict, the database is traversed to see if there is a version that does not include the conflicting jar package under the major version. If there is, the jar package version is replaced and the previous step is returned. If not, a jar package conflict is prompted and the import address of the jar package after the conflicting jar package is excluded is generated; Synchronously, if the jar package required in the project development process does not conflict with the existing jar package, an import address of the jar package required in the project development process is generated; The jar package required in the project development process is imported based on the import address.

7. The jar package importing method according to claim 6, characterized in that: The traversal of the database to see whether there is a version without conflicting jar packages under the major version also includes jar package analysis, and the jar package analysis includes: Get the jar package and all versions of the jar package; Parse the basic jar package included in the jar package under each version; The jar package and the included basic jar package under each version are stored in the database.

8. A jar package importing device, characterized in that: include: The jar package acquisition module is used to obtain the jar package to be imported required by the software project; The conflict detection module is used to detect whether there is a jar package conflict based on the jar package to be imported; The conflict handling module is used to generate an import address based on the jar package to be imported when there is no jar package conflict, or to determine whether the jar package to be imported needs to be replaced when there is a jar package conflict; The version processing module is used to perform version change when version change is required and return to determine whether there is a jar conflict, or to prompt and exclude conflicting jar packages when version change is not required, and generate the import address of the jar package after the conflicting jar package is excluded; The jar package import module is used to perform jar package import based on the import address of the jar package after the conflicting jar packages are excluded.

9. An electronic device, comprising a memory, a processor, a communication interface and a communication bus, wherein the memory stores a computer program that can be run on the processor, and the memory and the processor communicate through the communication bus and the communication interface, characterized in that: When the processor executes the computer program, the jar package import method described in any one of claims 1 to 7 is implemented.

10. A readable storage medium storing program instructions, which, when read and executed by a computing device, enables the computing device to execute the jar package import method according to any one of claims 1 to 7.