Summary of the invention
In view of this, the object of the present invention is to provide a kind of starter and starting method, to overcome the problems referred to above, reduce the configuration effort amount of each Java stand-alone utility, reduce start-up cost.
For this reason, the open following technical scheme of the present invention:
A starter, comprises read module, path generation module and load-on module, wherein:
Described read module, be used for reading starter configuration file, and the application configuration file that reads described target Java stand-alone utility according to the application Profile Path of the target Java stand-alone utility receiving in advance, described starter configuration file comprises the common configuration that in advance the common configuration item of each Java stand-alone utility is configured gained, described common configuration comprises common class path classpath, and described application configuration file comprises application classpath;
Described path generation module, for utilizing the public classpath of described starter configuration file and the application classpath in described application configuration file to generate complete classpath;
Described load-on module, for based on described complete classpath, loads the entrance class of described target Java stand-alone utility, starts described target Java stand-alone utility.
Preferably, described starter also comprises daily record redirection module, and described daily record redirection module is for being redirected to daily record the file of daily record configuration appointment, and described configuration file is included in described application configuration file.
Preferably, described starter also comprises:
Encrypting module, class or the configuration file for the needs to described target Java stand-alone utility, encrypted are encrypted, and described configuration file is configuration file required when access destination is served in described Java stand-alone utility operational process.
Preferably, described starter also comprises:
Search module, during for other classes when except described target Java stand-alone utility is called described entrance class or loading configuration file, in described complete classpath, search described class or configuration file;
Deciphering module, while being encrypt file for the described class finding out or configuration file, is decrypted described class or described configuration file;
Return to module, for described class or configuration file are transferred to described target Java stand-alone utility, so that described target Java stand-alone utility continues operation.
Preferably, described starter also comprises:
Plug-in unit deployment module, while there is change for the code in described target Java stand-alone utility, the code that dynamic load changed;
Path hides module, for when described target Java stand-alone utility is moved, hide the corresponding information in classpath, to realize a show process key message, described process key message, comprises startup class title and the configuration file of Java Virtual Machine JVM parameter, application.
A starting method, comprising:
Read starter configuration file, and the application configuration file that reads described target Java stand-alone utility according to the application Profile Path of the target Java stand-alone utility receiving in advance, described starter configuration file comprises the common configuration that in advance the common configuration item of each Java stand-alone utility is configured gained, described common configuration comprises public classpath, and described application configuration file comprises application classpath;
Utilize public classpath in described starter configuration file and the application classpath in described application configuration file to generate complete classpath;
Based on described complete classpath, load the entrance class of described target Java stand-alone utility, start described target Java stand-alone utility.
Preferably, described method also comprises:
Daily record is redirected to the file of described daily record configuration appointment, described daily record configuration is included in described application configuration file.
Preferably, described method also comprises:
Class or configuration file that the needs of described target Java stand-alone utility are encrypted are encrypted, and described configuration file is configuration file required when access destination is served in described Java stand-alone utility operational process.
Preferably, described method also comprises:
When other classes except described target Java stand-alone utility is called described entrance class or loading configuration file, in described complete classpath, search described class or configuration file;
When the described class finding out or configuration file are encrypt file, described class or described configuration file are decrypted;
Described class or described configuration file are transferred to described target Java stand-alone utility, so that described target Java stand-alone utility continues operation.
Preferably, described method also comprises:
When there is change in the code of described target Java stand-alone utility, the code that dynamic load changed;
When the operation of described target java application, hide the corresponding information in classpath, to realize a show process key message, described process key message, comprises startup class title and the configuration file of JVM parameter, application.
The starter that the embodiment of the present invention provides, based on each Java stand-alone utility, need to have this actual disposition situation of similar configuration, the identical configuration item in advance each Java stand-alone utility being had is added to starter configuration file as common configuration item and carries out disposable configuration.Follow-up need to start target Java stand-alone utility time, by starter of the present invention, read common configuration in starter configuration file and the application configuration file of this target Java stand-alone utility, according to common configuration and the complete classpath of application configuration integrate, and then can, according to the entrance class of this complete classpath loaded targets Java stand-alone utility, start target Java stand-alone utility.
Visible, starter of the present invention is by carrying out disposable configuration using the identical configuration item of each Java stand-alone utility as common configuration in advance, realized for Java stand-alone utility and only needed the peculiar configuration item outside its common configuration to be configured, thereby, by starter of the present invention, can avoid each Java stand-alone utility to carry out complete startup configuration, reduce the configuration effort amount of each Java stand-alone utility, reduce start-up cost.
Embodiment
For making object, technical scheme and the advantage of the embodiment of the present invention clearer, below in conjunction with the accompanying drawing in the embodiment of the present invention, technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is the present invention's part embodiment, rather than whole embodiment.Embodiment based in the present invention, those of ordinary skills, not making the every other embodiment obtaining under creative work prerequisite, belong to the scope of protection of the invention.
The present invention discloses a kind of starter and starting method, this starter designs based on self-defining class value-added tax function, for the Java stand-alone utility on JVM being started and application programs is carried out other and administered and maintained work, below will to starter and the starting method of invention, be elaborated by each embodiment.
Embodiment mono-
The embodiment of the present invention one discloses a kind of starter, and as shown in Figure 1, this starter comprises read module 100, path generation module 200 and load-on module 300.
Applicant is through research discovery, although the configuration file of Java stand-alone utility is too complicated, each application needs similarly to configure, and in the work that a plurality of Java stand-alone utilities is started to configuration, has comprised a large amount of repetitive operation.Based on this situation, in order to reduce the workload that starts configuration, reduce application start cost, the present invention obtains the repetition of each Java stand-alone utility, identical configuration item in advance, using it as common configuration item, add in starter configuration file and carry out disposable configuration, this starter configuration file is as the common file of each Java stand-alone utility of follow-up startup.Particularly, common configuration comprises public classpath(class.path).
In prior art, when different platform operations, because the classpath literary style in Java startup command is different, need to write different configurations and script for Java stand-alone utility, for example configuration of file path under win: c: app conf; C: app lib, the configuration of file path: linux:/app/conf:/app/lib under linux.For this situation, the present invention, when configuration, by classpath unification is :/app/conf; / app/lib, has solved cross-platform problem.
Read module 100, be used for reading described starter configuration file, and the application configuration file that reads described target Java stand-alone utility according to the application Profile Path of the target Java stand-alone utility receiving in advance, described application configuration file comprises application classpath.
Particularly, before using, moving starter of the present invention, need in advance the Profile Path of target Java stand-alone utility be passed to starter of the present invention as parameter.In operational process of the present invention, read module 100 reads the application configuration file of target Java stand-alone utility according to this path receiving in advance.
, it should be noted that, the application configuration file of target Java stand-alone utility only comprises the peculiar configuration except common configuration of this destination application herein.
Read module 100 also reads this common configuration of public classpath from starter configuration file, in practical application scene, if read module 100 can not find starter configuration file, Use Defaults, default value refers to the properties configuration file under the same catalogue of starter.
Path generation module 200, for utilizing the common configuration of described starter configuration file and the application classpath in described application profiles to generate complete classpath.
The process that generates complete classpath is as follows:
If a) the application classpath in application configuration is the jar file pointing to one by one, JAR is added to application classpath;
B) if application classpath points to catalogue, all JAR in catalogue are added to application classpath;
C) merge application classpath and public classpath.
Load-on module 300, for based on described complete classpath, loads the entrance class of described target Java stand-alone utility, starts described target Java stand-alone utility.
Read module 100 and path generation module 200 have completed the initial work of starter, and afterwards, load-on module 300 is according to the complete classpath of gained, and the entrance class of loaded targets Java stand-alone utility, calls main method, start destination application.
Refer to Fig. 2, Fig. 2 shows the ultimate principle that application starter of the present invention starts Java stand-alone utility, as seen in Figure 2, difference with standard Java application start is, what the present invention first started is starter itself, and then starter is based on carrying out loaded targets application program in conjunction with common configuration with the complete classpath that application configuration draws.Thereby the present invention has realized by self-defining class value-added tax function and has started application program, and does not need the code of modifying target application program.
In sum, the starter that the embodiment of the present invention provides, based on each Java stand-alone utility, need to have this actual disposition situation of similar configuration, the identical configuration item in advance each Java stand-alone utility being had is added to starter configuration file as common configuration item and carries out disposable configuration.Follow-up need to start target Java stand-alone utility time, by starter of the present invention, read common configuration in starter configuration file and the application configuration file of this target Java stand-alone utility, according to common configuration and the complete classpath of application configuration integrate, and then can, according to the entrance class of this complete classpath loaded targets Java stand-alone utility, start target Java stand-alone utility.
Visible, starter of the present invention is by carrying out disposable configuration using the identical configuration item of each Java stand-alone utility as common configuration in advance, realized for Java stand-alone utility and only needed the peculiar configuration item outside its common configuration to be configured, thereby, by starter of the present invention, can avoid each Java stand-alone utility to carry out complete startup configuration, reduce the configuration effort amount of each Java stand-alone utility, reduce start-up cost.
Embodiment bis-
The embodiment of the present invention two discloses the another kind of structure of starter, outside its each module in having comprised embodiment mono-, refers to Fig. 3, also comprises daily record redirection module 400, encrypting module 500, searches module 600, deciphering module 700 and return to module 800.
Daily record redirection module 400, for being redirected to daily record the file of daily record configuration appointment.
Wherein, described daily record configuration is included in application configuration file, and, in the present embodiment two, application configuration file, having comprised on the basis of application classpath, also comprises daily record configuration.
Encrypting module 500, the class of encrypting for the needs to described target Java stand-alone utility or configuration file or code file are encrypted.
Wherein, required configuration file when this configuration file is specially the service of access destination in Java stand-alone utility operational process, for example during accessing database, Java stand-alone utility need to be used the configuration file that has comprised the configuration items such as database account, password to realize the access to database.
In the present embodiment, the encryption configuration item identical, that repeat of each Java stand-alone utility is put into starter configuration file and carry out disposable configuration, be that starter configuration file comprises public classpath and encryption configuration item, it should be noted that, in starter configuration file, included content is not limited to above-mentioned public classpath and encryption configuration item, when concrete use is of the present invention, can according to the actual disposition situation of each application, to the included content of starter configuration file, be stipulated by those skilled in the art.
Starter of the present invention provides encryption/decryption functionality by encrypting module 500 and deciphering module 700, when the class of target Java stand-alone utility or configuration file or code file have encryption requirements, it is encrypted, and before loading, carry out corresponding deciphering, to guarantee that destination application normally starts, moves.
The respective code file of target Java stand-alone utility is encrypted and can avoids the decompiling of user to Java code.
Search module 600, during for other classes when except described target Java stand-alone utility is called described entrance class or loading configuration file, in described complete classpath, search described class or configuration file.
Particularly, target Java stand-alone utility starts after also normal operation, when other classes of this application call or loading configuration file, control is got back to starter of the present invention again, searches module 600 and in complete classpath, searches the required class of calling or configuration file.
The present embodiment adopts ClassLoader (class loading) mechanism of JVM, when application program reads class file (class file) at every turn, will call the self-defined ClassLoader of starter, thereby realize control, gets back to starter.
Deciphering module 700, while being encrypt file for the described class finding out or configuration file, is decrypted described class or configuration file.
Return to module 800, for described class or configuration file are transferred to described target Java stand-alone utility, so that described target Java stand-alone utility continues operation.
The present embodiment two is improving and supplementing starter in embodiment mono-, the encryption/decryption functionality that encrypting module 500, deciphering module 700 provide, the account number, password etc. that have solved database need to encrypt the problem of storage, do not affecting and do not needing to revise under the prerequisite of application program, class and file that can application programs be encrypted, code file by application programs is encrypted has avoided the decompiling of user to Java code, the security that has improved application program and project.
Embodiment tri-
The embodiment of the present invention three continues the starter in embodiment mono-, two improve and optimize, and as shown in Figure 4, it also comprises that plug-in unit deployment module 900 and path hide module 1000 on the basis of each module that has comprised above introduction.
Plug-in unit deployment module 900, while there is change for the code in described target Java stand-alone utility, the code that dynamic load changed.
The Java stand-alone utility of prior art can not realize plug-in unitization and dispose, the code can not dynamic load change, when code after changing, need to stop and restarting applying and realize the loading of code after changing.For this drawback, the invention provides plug-in unit deployment module 900, solve this problem, realize the function of the code that dynamic load changed.Particularly, this module adds check code to code in advance, and code designation when change change check code simultaneously, thereby when this module finds that the check code of code follows check code in internal memory inconsistent, can assert that code changes, and load the code changing.
Path hides module 1000, for when described target java application moves, hide the corresponding information in classpath, to realize a show process key message, described process key message, comprises startup class title and the configuration file of JVM parameter, application.
In prior art, when the java application of standard starts, class.path is very long, while causing checking process, be difficult to identify this shortcoming of application that need to search, path of the present invention hides module 1000 and hides classpath, and minimizing process shows information, only show key message, to improve the efficiency of maintenance work.
Embodiment bis-and embodiment tri-are the optimization to starter in embodiment mono-, be that starter of the present invention not only can be for starting Java stand-alone utility, by starter of the present invention, starting after application program, starter also will be taken over loading and the class loading work of file in whole application program operational process, be responsible for the processing in path, the application programs such as the enciphering/deciphering of file administer and maintain operation, and the whole course of work does not need to revise the code of application program, improved administering and maintaining of Java stand-alone utility.
Embodiment tetra-
The embodiment of the present invention four discloses a kind of starting method, and it is corresponding with the above disclosed starter of each embodiment.
First, corresponding to embodiment mono-, a kind of flow process of the present embodiment four open starting methods, refers to Fig. 5, comprising:
S1: read starter configuration file, and the application configuration file that reads described target Java stand-alone utility according to the application Profile Path of the target Java stand-alone utility receiving in advance, described starter configuration file comprises that the common configuration item based on to each Java stand-alone utility is configured the common configuration of gained, described common configuration comprises public classpath, and described application configuration file comprises application lasspath.
S2: utilize public classpath in described starter configuration file and the application classpath in described application configuration file to generate complete classpath.
S3: based on described complete classpath, load the entrance class of described target Java stand-alone utility, start described target Java stand-alone utility.
Corresponding to the structure of starter in embodiment bis-, the present embodiment four continues the another kind of flow process of open starting method, and as shown in Figure 6, it,, except comprising above step S1, S2, S3, also comprises:
S4: the file that daily record is redirected to daily record configuration appointment.
Wherein, described daily record configuration is included in application configuration file.
This step S4 is specifically between step S2 and S3.
S5: when other classes except described target Java stand-alone utility is called described entrance class or loading configuration file, search described class or configuration file in described complete class.path;
Described configuration file is configuration file required when access destination is served in described Java stand-alone utility operational process.
S6: when the described class finding out or configuration file are encrypt file, described class or configuration file are decrypted;
S7: described class or configuration file are transferred to described target Java stand-alone utility, so that described target Java stand-alone utility continues operation.
Corresponding to embodiment tri-, above-mentioned starting method also comprises:
When there is change in the code of described target Java stand-alone utility, the code that dynamic load changed;
When the operation of described target java application, hide the corresponding information in classpath, to realize a show process key message, described process key message, comprises startup class title and the configuration file of JVM parameter, application.
Fig. 7, for the present invention that utilizes that the present embodiment provides starts, manages an instantiation of Java stand-alone utility, comprises the steps:
S701: start starter.
S702: starter reads the common configuration in starter configuration file, if can not find configuration file, Uses Defaults.
Wherein, default value refers to the properties configuration file under the same catalogue of starter.
S703: the application configuration of reading the configuration of Java stand-alone utility.
Application configuration specifically comprises application classpath, daily record configuration etc.
S704: in conjunction with common configuration and the complete classpath of application configuration integrate.
S705: the file that daily record is redirected to configuration appointment.
S706: starter initialization completes.The entrance class of starter loading application programs, calls main method, starts java stand-alone utility.
S707: application program is normally moved.
S708: when application program need to be called other class or loading configuration file, control is got back to starter.
S709: starter is searched class or the configuration file that need to call in classpath.
S710: the file whether file that starter inspection finds out was encrypted, is if it is decrypted.
S711: giving application program by the class of loading or file.Application program continues operation, and goes to step S707.
For the disclosed starting method of the embodiment of the present invention four, because it is corresponding with above embodiment mono-to embodiment tri-disclosed starter, so that describes is fairly simple, relevant similarity refers to the explanation of starter part in embodiment mono-to embodiment tri-, no longer describes in detail herein.
In sum, the present invention carries out disposable configuration by the repeated configuration item of each Java stand-alone utility being put in the configuration file of starter, has reduced the workload that starts configuration, has reduced the start-up cost of application program; After application program launching, starter of the present invention is taken over loading and the class loading work of file in whole application program operational process, is responsible for the processing in path, the application programs such as the enciphering/deciphering of file administer and maintain operation; Compared with prior art, the present invention is by hiding classpath, and the process that reduced shows information, has improved maintenance work efficiency; Do not affecting and do not needing to revise under the prerequisite of application program, class and file that can application programs be encrypted, and improve the security of application program and project; By the code file of application programs, encrypt to avoid the decompiling of client to Java code; The plug-in unitization of using self defined class value-added tax function to realize application is disposed, and does not more need re-launching applications during fresh code; And avoided the cross-platform problem of the different literary styles of the classpath in Java startup command under different platform, improved administering and maintaining of java application.
It should be noted that, each embodiment in this instructions all adopts the mode of going forward one by one to describe, and each embodiment stresses is the difference with other embodiment, between each embodiment identical similar part mutually referring to.
While for convenience of description, describing above device, system, with function, be divided into various modules or unit is described respectively.Certainly, when implementing the application, the function of each module or unit can be realized in same or a plurality of software and/or hardware.
As seen through the above description of the embodiments, those skilled in the art can be well understood to the mode that the application can add essential general hardware platform by software and realizes.Understanding based on such, the part that the application's technical scheme contributes to prior art in essence in other words can embody with the form of software product, this computer software product can be stored in storage medium, as ROM/RAM, magnetic disc, CD etc., comprise that some instructions are with so that a computer equipment (can be personal computer, server, or the network equipment etc.) carry out the method described in some part of each embodiment of the application or embodiment.
The above is only the preferred embodiment of the present invention; it should be pointed out that for those skilled in the art, under the premise without departing from the principles of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.