简体   繁体   中英

How to pack a library in a jar file?

I am new to working with any native library and this question might seem stupid so please bear with me.

I downloaded LTI-CIVIL to capture video input from webcam. It requires me to create a library in Eclipse and point out the location of the native files.

Assuming the native dlls are located at E:\\files\\lti-civil\\src\\native\\ms(x86) , I want to add these along with the jar file and make a standalone application that I can send to my friends.

Currently, I can run the program from Eclipse itself as it points to E:\\blah_blah but it may not be the case on other person's computer

Now, how do I pack these so that I can make a stand alone application ? do I create a folder in src of Eclipse and add the folder there or what ?

Take a look at this question/answer . As it covers what you are trying to do.

Just to cover what that answers says to do is package up the .dlls inside a .jar. Include that .jar inside your project. Before you run you extract them to a temp folder and tell your program to use that location.

To make a self contained JAR from Eclipse do the following steps.

第1步

Right click on your project and select Export

第2步

Under Java select Runnable JAR File

第三步

Select extract required libraries into generated JAR

This would allow you to send a single stand alone application to send to who you like.

The DLLs cannot be packed in a jar file because Java cannot load DLLs from an archive file on Windows. One possibility is to distribute something that includes the Java program (as a .jar) and the DLLs separately, and both are extracted on installation.

Popular choices are: a ZIP file the user would have to extract manually, a self-extracting ZIP file, or a "setup" program generated for example by InnoSetup .

Another possibility is to pack the DLL in the .jar file and have the application extract it on startup, for example into a temporary directory.

Once the DLL is on the file system you can load it with System.load or System.loadLibrary .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM