An SO User
An SO User

Reputation: 24998

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 ?

Upvotes: 2

Views: 7699

Answers (2)

Joni
Joni

Reputation: 111239

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.

Upvotes: 2

Halfwarr
Halfwarr

Reputation: 8103

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.

Step 1

Right click on your project and select Export

Step 2

Under Java select Runnable JAR File

Step 3

Select extract required libraries into generated JAR

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

Upvotes: 4

Related Questions