Summary of the invention
Often perform a Powershell script will create an independently process to solve java applet in prior art, cause the problem taking too much system resource, embodiments provide a kind of java applet manner of execution and device.Described technical scheme is as follows:
On the one hand, the embodiment of the present invention provides a kind of java applet manner of execution, and described method comprises:
Load dynamic link library file, described dynamic link library file comprises: for creating the realization of first nation method in Powershell script execution environment pond and the realization for the second nation method of performing Powershell script;
Call described first nation method, create Powershell script execution environment pond, described Powershell script execution environment pond comprises multiple Powershell script execution environment;
Call described second nation method, in described Powershell script execution environment, perform the Powershell script in described java applet;
Return Powershell script execution result.
In a kind of implementation of the embodiment of the present invention, described dynamic link library file also comprises the realization of the 3rd nation method relying on class libraries for pre-loaded Powershell script, and described method also comprises:
Before calling described second nation method, call described 3rd nation method, in each described Powershell script execution environment, pre-loaded Powershell script relies on class libraries.
In the another kind of implementation of the embodiment of the present invention, described loading dynamic link library file, comprising:
Load the class file for performing Powershell script, described class file comprises the statement of the title of called dynamic link library, and the statement of described first nation method, described second nation method and described 3rd nation method;
According to the title of the dynamic link library of described class file state, load described dynamic link library file.
In the another kind of implementation of the embodiment of the present invention, described method also comprises:
Generate described dynamic link library file and described class file.
In the another kind of implementation of the embodiment of the present invention, the described dynamic link library file of described generation and described class file, comprising:
Obtain Java file, described Java file comprises the statement of the title of called dynamic link library, and the statement of described first nation method, described second nation method and described 3rd nation method;
Compile described Java file, obtain described class file;
According to described class file generated Java local interface header file;
Obtain and compile C# code, generate CS file, described C# code comprises the introducing of described Java local interface header file, and the realization of described first nation method stated in described header file, described second nation method and described 3rd nation method;
Described CS file is compiled as described dynamic link library file.
In the another kind of implementation of the embodiment of the present invention, the described dynamic link library file of described generation and described class file, comprising:
Obtain and compile C# code, generate CS file, described C# code comprises the realization of described first nation method, described second nation method and described 3rd nation method;
Described CS file is compiled as described dynamic link library file;
Use JNI4NET compilation tool to compile described dynamic link library file, obtain described class file.
On the other hand, the embodiment of the present invention additionally provides a kind of java applet actuating unit, and described device comprises:
Load module, for loading dynamic link library file, described first dynamic link library file comprises: for creating the realization of first nation method in Powershell script execution environment pond and the realization for the second nation method of performing Powershell script;
First processing module, for calling described first nation method, create Powershell script execution environment pond, described Powershell script execution environment pond comprises multiple Powershell script execution environment;
Second processing module, for calling described second nation method, performs the Powershell script in described java applet in described Powershell script execution environment;
Output module, for returning Powershell script execution result.
In a kind of implementation of the embodiment of the present invention, described dynamic link library file also comprises the realization of the 3rd nation method relying on class libraries for pre-loaded Powershell script, and described device also comprises:
3rd processing module, for before calling described second nation method, calls described 3rd nation method, and in each described Powershell script execution environment, pre-loaded Powershell script relies on class libraries.
In the another kind of implementation of the embodiment of the present invention, described load module, comprising:
Loading unit, for loading the class file for performing Powershell script, described class file comprises the statement of the title of called dynamic link library, and the statement of described first nation method, described second nation method and described 3rd nation method;
Performance element, for the title of the dynamic link library according to described class file state, loads described dynamic link library file.
In the another kind of implementation of the embodiment of the present invention, described device also comprises:
Generation module, for generating described dynamic link library file and described class file.
In the another kind of implementation of the embodiment of the present invention, described generation module, comprising:
Acquiring unit, for obtaining Java file, described Java file comprises the statement of the title of called dynamic link library, and the statement of described first nation method, described second nation method and described 3rd nation method;
First compilation unit, for compiling described Java file, obtains described class file;
Second compilation unit, for according to described class file generated Java local interface header file;
3rd compilation unit, for obtaining and compiling C# code, generate CS file, described C# code comprises the introducing of described Java local interface header file, and the realization of described first nation method stated in described header file, described second nation method and described 3rd nation method;
4th compilation unit, for being compiled as described dynamic link library file by described CS file.
In the another kind of implementation of the embodiment of the present invention, described generation module, comprising:
5th compilation unit, for obtaining and compiling C# code, generate CS file, described C# code comprises the realization of described first nation method, described second nation method and described 3rd nation method;
6th compilation unit, for being compiled as described dynamic link library file by described CS file;
7th compilation unit, for using JNI4NET compilation tool to compile described dynamic link library file, obtains described class file.
The beneficial effect that the technical scheme that the embodiment of the present invention provides is brought is:
By loading dll file, and the first nation method called in this DLL, create Powershell script execution environment pond, Powershell script execution environment pond comprises multiple Powershell script execution environment, call the second nation method in DLL, perform the Powershell script in java applet; On the one hand, owing to have employed nation method to perform Powershell script, therefore new process can not be created when performing Powershell script, simultaneously, multiple Powershell script execution environment is comprised in Powershell script execution environment pond, make it possible to perform multiple Powershell script simultaneously, avoid an often execution Powershell script and will create an independently process, the problem of the wasting of resources caused; On the other hand, the 3rd nation method is also comprised in dll file, behind establishment Powershell script execution environment pond, can be loaded in Powershell script execution environment and rely on class libraries by the 3rd nation method, shorten the time that java applet performs Powershell script.
Embodiment
For making the object, technical solutions and advantages of the present invention clearly, below in conjunction with accompanying drawing, embodiment of the present invention is described further in detail.
Embodiment one
Embodiments provide a kind of java applet manner of execution, see Fig. 1, the method comprises:
Step 101: load DLL(Dynamic Link Library, dynamic link library) file, this dll file comprises: the Native(for creating Powershell script execution environment pond is local) realization of method and the realization for performing Powershell script the 2nd Native method.
This dll file is for performing the Powershell script in java applet.
Step 102: call a Native method, create Powershell script execution environment pond, Powershell script execution environment pond comprises multiple Powershell script execution environment.
Step 103: call the 2nd Native method, performs the Powershell script in java applet in Powershell script execution environment.
Step 104: return Powershell script execution result.
The embodiment of the present invention is by loading dll file, and the Native method called in this DLL, create Powershell script execution environment pond, Powershell script execution environment pond comprises multiple Powershell script execution environment, call the 2nd Native method in DLL, perform the Powershell script in java applet; On the one hand, owing to have employed Native method to perform Powershell script, therefore new process can not be created when performing Powershell script, simultaneously, multiple Powershell script execution environment is comprised in Powershell script execution environment pond, make it possible to perform multiple Powershell script simultaneously, avoid an often execution Powershell script and will create an independently process, the problem of the wasting of resources caused.
Embodiment two
Embodiments provide a kind of java applet manner of execution, see Fig. 2, the method comprises:
Step 201: obtain Java file, this Java file comprises the statement of the title of called DLL, and the statement of a Native method, the 2nd Native method and the 3rd Native method.
Java file is by Java code compilation.Wherein, a Native method, for creating Powershell script execution environment pond, comprises some script execution environment in pond, and the quantity of script execution environment can be specified in code.3rd Native method is used for pre-loaded Powershell script in above-mentioned script execution environment and relies on class libraries, when performing for script.2nd Native method is used for, when needs perform Powershell script, obtaining idle script execution environment, and then perform Powershell script from script execution environment pond.Wherein, script execution environment pond refers to the set providing object in multiple C# class libraries, and this object just can as being a Powershell script actuator, and namely each object can as a Powershell script execution environment.Java applet needs only to need when performing Powershell script to obtain idle script execution environment, heavily discharges this script execution environment again, so just can reuse script execution environment, form a script execution environment pond after executing.
Preferably, the script that the 3rd Native method loads relies on class libraries and comprises: required class libraries when all Powershell scripts comprised in this java applet perform.
Below the Java file in step 201 is illustrated:
Wherein, the Demo in System.LoadLibrary (" Demo ") is exactly the title of called DLL.
Step 202: compiling Java file, obtain class file, this class file is for performing Powershell script, and this class file comprises the statement of the title of called DLL, and the statement of a Native method, the 2nd Native method and the 3rd Native method.
This step can complete in Java compiler.
Step 203: according to class file generated JNI(Java Native Interface, Java local interface) header file.
Particularly, the class file obtained in Javah compile step 202 can be adopted in command-line tool, thus generate the header file including three native methods.
Step 204: obtain and compile C# code, generate CS file, C# code comprises the introducing of JNI header file, and the realization of the Native method stated in header file, the 2nd Native method and the 3rd Native method.
Step 205: CS file is compiled as dll file.
Above-mentioned steps 201 ~ 205 is the process generating dll file.The dll file finally generated is the DLL called stated in Java file in step 201.
Step 206: load this dll file, this dll file comprises the realization of a Native method, the 2nd Native method and the 3rd Native method.
Particularly, step 206 can comprise:
Step one, when java applet starts or perform Powershell script, load the class file produced in step 202.
The basic composition unit of java applet is class, and class comprises method.When java applet performs, class in java applet loads Lib(storehouse) in class file, realize the method that class comprises, above-mentioned execution Powershell script namely can method in certain class.
Step 2, title according to the DLL stated in this class file, load dll file.
Step 207: call a Native method, create Powershell script execution environment pond, Powershell script execution environment pond comprises multiple Powershell script execution environment.
Step 208: call the 3rd Native method, in each Powershell script execution environment, pre-loaded Powershell script relies on class libraries.
Step 209: call the 2nd Native method, performs the Powershell script in java applet in Powershell script execution environment.
Step 210: return Powershell script execution result.
The embodiment of the present invention is by loading dll file, and the Native method called in this DLL, create Powershell script execution environment pond, Powershell script execution environment pond comprises multiple Powershell script execution environment, call the 2nd Native method in DLL, perform the Powershell script in java applet; On the one hand, owing to have employed Native method to perform Powershell script, therefore new process can not be created when performing Powershell script, simultaneously, multiple Powershell script execution environment is comprised in Powershell script execution environment pond, make it possible to perform multiple Powershell script simultaneously, avoid an often execution Powershell script and will create an independently process, the problem of the wasting of resources caused; On the other hand, the 3rd Native method is also comprised in dll file, behind establishment Powershell script execution environment pond, can be loaded in Powershell script execution environment and rely on class libraries by the 3rd Native method, shorten the time that java applet performs Powershell script.
Embodiment three
Embodiments provide a kind of java applet manner of execution, the difference of the present embodiment and embodiment two is to adopt JNI4NET to realize to compile, and see Fig. 3, the method comprises:
Step 301: obtain and compile C# code, generate CS file, C# code comprises the realization of a Native method, the 2nd Native method and the 3rd Native method.
Wherein, a Native method, for creating Powershell script execution environment pond, comprises some script execution environment in pond, and the quantity of script execution environment can be specified in code.3rd Native method is used for pre-loaded Powershell script in above-mentioned script execution environment and relies on class libraries, when performing for script.2nd Native method is used for, when needs perform Powershell script, obtaining idle script execution environment, and then perform Powershell script from script execution environment pond.Wherein, script execution environment pond refers to the set providing object in multiple C# class libraries, and this object just can as being a Powershell script actuator, and namely each object can as a Powershell script execution environment.Program needs only to need when performing Powershell script to obtain idle script execution environment, heavily discharges this script execution environment again, so just can reuse script execution environment, form a script execution environment pond after executing.
Preferably, the script that the 3rd Native method loads relies on class libraries and comprises: required class libraries when all Powershell scripts comprised in this java applet perform.
Step 302: CS file is compiled as dll file.
Step 303: use JNI4NET compilation tool compiling dll file, obtain class file, this class file is for performing Powershell script, this class file comprises the statement of the title of called DLL, and the statement of a Native method, the 2nd Native method and the 3rd Native method.
Step 304: load dll file, this dll file comprises the realization of a Native method, the 2nd Native method and the 3rd Native method.
Particularly, step 304 can comprise:
Step one, when java applet starts or perform Powershell script, load the class file generated in step 303.
Step 2, title according to the DLL stated in this class file, load dll file.
Step 305: call a Native method, create Powershell script execution environment pond, Powershell script execution environment pond comprises multiple Powershell script execution environment.
Step 306: call the 3rd Native method, in each Powershell script execution environment, pre-loaded Powershell script relies on class libraries.
Step 307: call the 2nd Native method, performs the Powershell script in java applet in Powershell script execution environment.
Step 308: return Powershell script execution result.
The embodiment of the present invention is by loading dll file, and the Native method called in this DLL, create Powershell script execution environment pond, Powershell script execution environment pond comprises multiple Powershell script execution environment, call the 2nd Native method in DLL, perform the Powershell script in java applet; On the one hand, owing to have employed Native method to perform Powershell script, therefore new process can not be created when performing Powershell script, simultaneously, multiple Powershell script execution environment is comprised in Powershell script execution environment pond, make it possible to perform multiple Powershell script simultaneously, avoid an often execution Powershell script and will create an independently process, the problem of the wasting of resources caused; On the other hand, the 3rd Native method is also comprised in dll file, behind establishment Powershell script execution environment pond, can be loaded in Powershell script execution environment and rely on class libraries by the 3rd Native method, shorten the time that java applet performs Powershell script.
Embodiment four
Embodiments provide a kind of java applet actuating unit, see Fig. 4, this device comprises:
Load module 401, for loading dll file, dll file comprises: for creating the realization of a Native method in Powershell script execution environment pond and the realization for performing Powershell script the 2nd Native method;
First processing module 402, for calling a Native method, create Powershell script execution environment pond, Powershell script execution environment pond comprises multiple Powershell script execution environment;
Second processing module 403, for calling the 2nd Native method, performs the Powershell script in java applet in Powershell script execution environment;
Output module 404, for returning Powershell script execution result.
The embodiment of the present invention is by loading dll file, and the Native method called in this DLL, create Powershell script execution environment pond, Powershell script execution environment pond comprises multiple Powershell script execution environment, call the 2nd Native method in DLL, perform the Powershell script in java applet; On the one hand, owing to have employed Native method to perform Powershell script, therefore new process can not be created when performing Powershell script, simultaneously, multiple Powershell script execution environment is comprised in Powershell script execution environment pond, make it possible to perform multiple Powershell script simultaneously, avoid an often execution Powershell script and will create an independently process, the problem of the wasting of resources caused.
Embodiment five
Embodiments provide a kind of java applet actuating unit, see Fig. 5, this device comprises: load module 501, first processing module 502, second processing module 503 and output module 504.
Load module 501, for loading dll file, dll file comprises: for creating the realization of a Native method in Powershell script execution environment pond and the realization for performing Powershell script the 2nd Native method;
First processing module 502, for calling a Native method, create Powershell script execution environment pond, Powershell script execution environment pond comprises multiple Powershell script execution environment;
Second processing module 503, for calling the 2nd Native method, performs the Powershell script in java applet in Powershell script execution environment;
Output module 504, for returning Powershell script execution result.
Further, above-mentioned dll file also comprises the realization of the 3rd Native method relying on class libraries for pre-loaded Powershell script, and this device also comprises:
3rd processing module 505, for before calling the 2nd Native method, calls the 3rd Native method, and in each Powershell script execution environment, pre-loaded Powershell script relies on class libraries.
Wherein, a Native method, for creating Powershell script execution environment pond, comprises some script execution environment in pond, and the quantity of script execution environment can be specified in code.3rd Native method is used for pre-loaded Powershell script in above-mentioned script execution environment and relies on class libraries, when performing for script.2nd Native method is used for, when needs perform Powershell script, obtaining idle script execution environment, and then perform Powershell script from script execution environment pond.Wherein, script execution environment pond refers to the set providing object in multiple C# class libraries, and this object just can as being a Powershell script actuator, and namely each object can as a Powershell script execution environment.Program needs only to need when performing Powershell script to obtain idle script execution environment, heavily discharges this script execution environment again, so just can reuse script execution environment, form a script execution environment pond after executing.
Preferably, the script that the 3rd Native method loads relies on class libraries and comprises: required class libraries when all Powershell scripts comprised in this java applet perform.
In a kind of implementation of the embodiment of the present invention, load module 501 can comprise:
Loading unit, for when java applet starts or perform Powershell script, load the class file for performing Powershell script, class file comprises the statement of the title of called DLL, and the statement of a Native method, the 2nd Native method and the 3rd Native method;
Performance element, for the title of the DLL according to class file state, loads dll file.
Further, device also comprises:
Generation module 506, for generating dll file and class file.
In a kind of implementation of the embodiment of the present invention, generation module 506 comprises:
Acquiring unit, for obtaining Java file, Java file comprises the statement of the title of called DLL, and the statement of a Native method, the 2nd Native method and the 3rd Native method;
First compilation unit, for compiling Java file, obtains class file;
Second compilation unit, for according to class file generated JNI header file;
3rd compilation unit, for obtaining and compiling C# code, generate CS file, C# code comprises the introducing of JNI header file, and the realization of the Native method stated in header file, the 2nd Native method and the 3rd Native method;
4th compilation unit, for being compiled as dll file by CS file.
In the another kind of implementation of the embodiment of the present invention, generation module 506 comprises:
5th compilation unit, for obtaining and compiling C# code, generate CS file, C# code comprises the realization of a Native method, the 2nd Native method and the 3rd Native method;
6th compilation unit, for being compiled as dll file by CS file;
7th compilation unit, for using JNI4NET compilation tool to compile dll file, obtains class file.
The embodiment of the present invention is by loading dll file, and the Native method called in this DLL, create Powershell script execution environment pond, Powershell script execution environment pond comprises multiple Powershell script execution environment, call the 2nd Native method in DLL, perform the Powershell script in java applet; On the one hand, owing to have employed Native method to perform Powershell script, therefore new process can not be created when performing Powershell script, simultaneously, multiple Powershell script execution environment is comprised in Powershell script execution environment pond, make it possible to perform multiple Powershell script simultaneously, avoid an often execution Powershell script and will create an independently process, the problem of the wasting of resources caused; On the other hand, the 3rd Native method is also comprised in dll file, behind establishment Powershell script execution environment pond, can be loaded in Powershell script execution environment and rely on class libraries by the 3rd Native method, shorten the time that java applet performs Powershell script.
It should be noted that: the java applet actuating unit that above-described embodiment provides is when performing Powershell script, only be illustrated with the division of above-mentioned each functional module, in practical application, can distribute as required and by above-mentioned functions and be completed by different functional modules, inner structure by device is divided into different functional modules, to complete all or part of function described above.In addition, the java applet actuating unit that above-described embodiment provides and java applet manner of execution embodiment belong to same design, and its specific implementation process refers to embodiment of the method, repeats no more here.
The invention described above embodiment sequence number, just to describing, does not represent the quality of embodiment.
One of ordinary skill in the art will appreciate that all or part of step realizing above-described embodiment can have been come by hardware, the hardware that also can carry out instruction relevant by program completes, described program can be stored in a kind of computer-readable recording medium, the above-mentioned storage medium mentioned can be ROM (read-only memory), disk or CD etc.
The foregoing is only preferred embodiment of the present invention, not in order to limit the present invention, within the spirit and principles in the present invention all, any amendment done, equivalent replacement, improvement etc., all should be included within protection scope of the present invention.