CN106484467A - Method for loading dynamic library in jar package by java - Google Patents

Method for loading dynamic library in jar package by java Download PDF

Info

Publication number
CN106484467A
CN106484467A CN201610840741.XA CN201610840741A CN106484467A CN 106484467 A CN106484467 A CN 106484467A CN 201610840741 A CN201610840741 A CN 201610840741A CN 106484467 A CN106484467 A CN 106484467A
Authority
CN
China
Prior art keywords
dynamic base
file
java
jar bag
loads
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201610840741.XA
Other languages
Chinese (zh)
Inventor
郭运艳
解豪
解一豪
高峰
柳廷娜
衣秀
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Software Group Co Ltd
Original Assignee
Inspur Software Group Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur Software Group Co Ltd filed Critical Inspur Software Group Co Ltd
Priority to CN201610840741.XA priority Critical patent/CN106484467A/en
Publication of CN106484467A publication Critical patent/CN106484467A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention discloses a method for loading a dynamic library in a jar packet by java, which comprises the following implementation processes: and decompressing the dynamic library in the jar package to a temporary file directory, loading through an absolute path, and deleting the generated dynamic library at the end of the program. Compared with the prior art, the method for loading the dynamic library in the jar package by the java can provide the specified position in the jar package or in the jar package for loading, meets the requirement of loading the dynamic library, ensures the cleanness of the system, and has strong practicability, wide application range and easy popularization.

Description

A kind of method that java loads jar bag the inside dynamic base
Technical field
The present invention relates to technical field of software development, specifically a kind of practical, java loads jar bag the inside and moves The method in state storehouse.
Background technology
Dynamic load jar bag, often may require that in actual development and uses, more particularly, to the relation of platform and business when Wait, service logic part can independently go out to give business square tube reason, and business side only needs to provide jar bag, just can be on platform Run.
Do not provide the dynamic base method loading in jar bag in the prior art method, but java program carries to outside It is all to be existed with jar packet mode for program, there is presently no a kind of method can refer to by jar bag inside or jar bag Fixed position is gone to load jar bag the inside dynamic base, has had a strong impact on the carrying out of software development, in consideration of it, now providing one kind to be based on Java loads the method for dynamic base inside jar bag solving this problem.
Content of the invention
The technical assignment of the present invention is for above weak point, provides a kind of practical, java to load inside jar bag The method of dynamic base.
A kind of method that java loads dynamic base inside jar bag, it is realized process and is:Dynamic in decompression jar bag first Storehouse, to temporary file directory, is then loaded by absolute path, deletes the dynamic base producing in EP (end of program).
It implements process:
In the way of file stream, first read the dynamic base in jar bag, this dynamic base determines by judging system type, wherein dynamic State storehouse suffix is suffix;
Then by way of file output stream is with byte stream, by the temporary folder of the file stream writing system of above-mentioned reading Under;
Load this dynamic base;
Using using the dynamic base temporary file deleting function deletion generation at the end of loading.
Judge that system type determines the dynamic base in jar bag by calling System.getProperty (), then when When having required dynamic base under certain class place jar bag certain file directory lower, obtained by function getResourceAsStream Take file input stream.
Described temporary folder pass through System.getProperty () obtain, then this catalogue newly-built one entitled The file of " file directory title adds timestamp ", timestamp is obtained by timing tool class, and records this document position.
Load dynamic base using the mode of System.load (), wherein System.load () refers to that parameter is library file Absolute path.
Dynamic base deletes generated temporary file using the deleteOnExit () function under File at the end of loading;When When not coming into force under windows, using Runtime.getRuntime () .addShutdownHook come using java order execution Main function executes deletion.
The method that a kind of java of the present invention loads jar bag the inside dynamic base, has advantages below:
A kind of java that the present invention provides loads the method for jar bag the inside dynamic base it is provided that inside jar bag or jar bag The position inside specified is gone to load, meet demand when loading dynamic base it is ensured that system clean, and then user friendly exploitation makes With, practical, applied widely it is easy to promote.
Specific embodiment
With reference to specific embodiment, the invention will be further described.
The method that a kind of java of the present invention loads dynamic base inside jar bag, it is realized process and is:Decompress jar bag first In dynamic base to temporary file directory, then loaded by absolute path, in EP (end of program) delete produce dynamic base.
It implements process:
In the way of file stream, first read the dynamic base in jar bag, this dynamic base determines by judging system type, wherein dynamic State storehouse suffix is suffix;
Then by way of file output stream is with byte stream, by the temporary folder of the file stream writing system of above-mentioned reading Under;
Load this dynamic base;
Using using the dynamic base temporary file deleting function deletion generation at the end of loading.
Judge that system type determines the dynamic base in jar bag by calling System.getProperty (), System.getProperty () is a static method, is used for all of system variable is set out, then when certain class is located When having required dynamic base under jar bag certain file directory lower, file input is obtained by function getResourceAsStream Stream.
Described temporary folder pass through System.getProperty () obtain, then this catalogue newly-built one entitled The file of " file directory title adds timestamp ", timestamp is obtained by timing tool class, and records this document position.
Load dynamic base using the mode of System.load (), wherein System.load () refers to that parameter is library file Absolute path.
Dynamic base deletes generated temporary file using the deleteOnExit () function under File at the end of loading;When When not coming into force under windows, using Runtime.getRuntime () .addShutdownHook come using java order execution Main function executes deletion.
Described Runtime.getRuntime () .addShutdownHook increases a pass in Java Virtual Machine jvm The hook closing, when jvm closes, can configured in execution system all be added by method addShutdownHook Plus hook, after system has executed these hooks, jvm just can close, and it is clear that above-mentioned hook carries out internal memory when jvm closes The operation that reason, object are destroyed.
Load dynamic base sometimes to must necessarily be placed under the conditions of some in jar bag in external load, so being accomplished by elder generation Solution presses out, and decompressed position can not at will be placed, so demanding party is put under temp file, records this position, using exhausted To path load mode load, the file of generation need to be deleted when exiting it is ensured that system clean.
Specifically, the present invention provides an example and is described in detail:
In the way of file stream, first read the dynamic base in jar bag, dynamic base suffix is suffix, passes through System.getProperty (" os.name ") judges system type to determine;Under the place jar bag of certain class cls certain There is required dynamic base native.suffix under file directory dll, then pass through function cls.getResourceAsStream (dll/native.suffix) obtain file input stream
By, under the temporary folder temp of FileOutputStream writing system, temp passes through System.getProperty (" java.io.tmpdir ") obtains, then in the literary composition of the newly-built entitled dllfile=dll+time (timestamp) of this catalogue Part presss from both sides, and time passes through System.nanoTime () and obtains, and is to prevent from repeating, and records this document position nativefile =temp+dllfile/ native.suffix.
Generated temporary file is deleted using the deleteOnExit () function under File during whole EP (end of program), Do not come into force under windows, using Runtime.getRuntime () .addShutdownHook come using java order execution Main function executes deletion.
Above-mentioned specific embodiment is only the concrete case of the present invention, and the scope of patent protection of the present invention includes but is not limited to Above-mentioned specific embodiment, a kind of any java meeting the present invention loads the claim of the method for jar bag the inside dynamic base The suitable change or replacement that book and any described technical field those of ordinary skill is done to it, all should fall into the present invention's Scope of patent protection.

Claims (6)

1. a kind of java loads the method for dynamic base inside jar bag it is characterised in that it realizes process is:Decompress jar bag first In dynamic base to temporary file directory, then loaded by absolute path, in EP (end of program) delete produce dynamic base.
2. a kind of java according to claim 1 loads the method for jar bag the inside dynamic base it is characterised in that it is concrete The process of realization is:
In the way of file stream, first read the dynamic base in jar bag, this dynamic base determines by judging system type, wherein dynamic State storehouse suffix is suffix;
Then by way of file output stream is with byte stream, by the temporary folder of the file stream writing system of above-mentioned reading Under;
Load this dynamic base;
Using using the dynamic base temporary file deleting function deletion generation at the end of loading.
3. a kind of java according to claim 2 loads the method for jar bag the inside dynamic base it is characterised in that passing through to adjust Judge that system type determines the dynamic base in jar bag with System.getProperty (), then as certain class place jar When having required dynamic base under bag certain file directory lower, file input stream is obtained by function getResourceAsStream.
4. a kind of java according to claim 2 loads the method for jar bag the inside dynamic base it is characterised in that described face When file pass through System.getProperty () obtain, then in newly-built entitled " the file directory title of this catalogue Add timestamp " file, timestamp is obtained by timing tool class, and records this document position.
5. a kind of java according to claim 2 loads the method for jar bag the inside dynamic base it is characterised in that using The mode of System.load () loads dynamic base, and wherein System.load () refers to the absolute path that parameter is library file.
6. a kind of java according to claim 2 loads the method for dynamic base inside jar bag it is characterised in that dynamic base Generated temporary file is deleted using the deleteOnExit () function under File at the end of loading;When not giving birth under windows During effect, using Runtime.getRuntime () .addShutdownHook come using java order execution main function execution Delete.
CN201610840741.XA 2016-09-22 2016-09-22 Method for loading dynamic library in jar package by java Pending CN106484467A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610840741.XA CN106484467A (en) 2016-09-22 2016-09-22 Method for loading dynamic library in jar package by java

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610840741.XA CN106484467A (en) 2016-09-22 2016-09-22 Method for loading dynamic library in jar package by java

Publications (1)

Publication Number Publication Date
CN106484467A true CN106484467A (en) 2017-03-08

Family

ID=58267862

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610840741.XA Pending CN106484467A (en) 2016-09-22 2016-09-22 Method for loading dynamic library in jar package by java

Country Status (1)

Country Link
CN (1) CN106484467A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114691242A (en) * 2022-04-20 2022-07-01 深圳市元征软件开发有限公司 Software function implementation method, device, equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102541598A (en) * 2011-12-26 2012-07-04 深圳联友科技有限公司 Method and system for dynamically loading component
CN105389222A (en) * 2015-12-15 2016-03-09 中国科学院声学研究所 Method, apparatus and system for dynamically calling native interface
CN105760196A (en) * 2016-02-18 2016-07-13 福建天晴数码有限公司 Detection method and system for pluggable plug-in program

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102541598A (en) * 2011-12-26 2012-07-04 深圳联友科技有限公司 Method and system for dynamically loading component
CN105389222A (en) * 2015-12-15 2016-03-09 中国科学院声学研究所 Method, apparatus and system for dynamically calling native interface
CN105760196A (en) * 2016-02-18 2016-07-13 福建天晴数码有限公司 Detection method and system for pluggable plug-in program

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
元澈: "将动态库打包在Jar包并调用的方法", 《HTTPS://BLOG.CSDN.NET/AB7253957/ARTICLE/DETAILS/52242874》 *
永远向前的麦田: "java加载jar包中的库资源", 《HTTPS://BLOG.CSDN.NET/PEYTONZHAO/ARTICLE/DETAILS/51778454》 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114691242A (en) * 2022-04-20 2022-07-01 深圳市元征软件开发有限公司 Software function implementation method, device, equipment and storage medium

Similar Documents

Publication Publication Date Title
US7735138B2 (en) Method and apparatus for performing antivirus tasks in a mobile wireless device
US7735059B2 (en) Winforms control hosting in unmanaged applications
EP3062234A1 (en) System, method and computer program product for content/context sensitive scanning utilizing a mobile communication device
CN102831344B (en) Course handling method and device
US8417744B2 (en) Techniques to manage a collection of objects in heterogeneous environments
CN108229107B (en) Shelling method and container for Android platform application program
CN102567033A (en) Class pre-loading method and device based on embedded real-time Java virtual machine
US9817638B2 (en) Systems and methods for injecting code into an application
CN106484467A (en) Method for loading dynamic library in jar package by java
JP6164508B2 (en) Data processing system security apparatus and security method
CN102968321A (en) Application program installation device and application program installation method
EP3128458B1 (en) User-mode component injection and atomic hooking
CN106169048B (en) File delet method, device and electronic equipment
CN106778269B (en) Method and device for preventing injection of driving layer and client
WO2002006951A3 (en) Computer software installation
US20180285141A1 (en) Thread operation across virtualization contexts
CN108681491B (en) File decoupling method and system
CN107291909B (en) Data processing method and system
CN109739548A (en) Program packaging method, program packing apparatus and computer readable storage medium
CN102830976B (en) A kind of software architecture dynamic evolution method based on incidence matrix
CN1332305C (en) Module life period managing method
CN110597738B (en) Memory release method, terminal and computer readable storage medium
CN111045746A (en) Code expansion method and framework
CN106203070A (en) Drive loading prevention method and device
CN107643959A (en) Image file treating method and apparatus

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20170308