2

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 ?

An SO User
  • 24,612
  • 35
  • 133
  • 221

2 Answers2

4

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.

Community
  • 1
  • 1
Halfwarr
  • 7,853
  • 6
  • 33
  • 51
2

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.

Joni
  • 108,737
  • 14
  • 143
  • 193
  • JAR files don't have to be compressed though. Or are you saying Windows cannot read DLL's from any archive file? – Perception Mar 28 '13 at 15:32
  • Alternatively, you can pack the DLL/s in the jar file, and have the application automatically extract the appropriate DLLs before running. OSGi does this. – Andy Thomas Mar 28 '13 at 15:38
  • Yes, @Perception, that's what I mean. My use of "compressed file" can be misleading, will edit. – Joni Mar 28 '13 at 15:57
  • Thanks @AndyThomas-Cramer, will edit to mention that possibility. – Joni Mar 28 '13 at 16:04