10

I am having trouble exporting my java project from eclipse as a jar executable file. My java project uses an external library (its called jri). I have exported the jri.jar file and set the library path for its native library in eclipse, and it works great in development in eclipse. However, when I export it as an executable jar file I get the following error:

Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.

I have placed a folder called lib in the same directory as my project's jar; this lib folder contains jri's native library. jri's native library is not in one file but in a folder. This is the same setup I have in eclipse.

The way I am exporting my project in eclipse is

Export...
Java > Runnable JAR file
Copy required libraries into a sub folder next to the generated Jar
Finish

And my folder is organized like this

folder project
  project.jar
  project_lib
    jri.jar
    jri native library folder  

The MANIFEST.MF of my project.jar is:

Manifest-Version: 1.0
Class-Path: . project_lib/jri.jar
Main-Class: index

What I want to achieve is to give another person a folder including project.jar and anything else needed so she/he can run it without needing to install anything else. Thanks so much

JoshDM
  • 4,939
  • 7
  • 43
  • 72
Julio Diaz
  • 9,067
  • 19
  • 55
  • 70
  • If you hate dont use it, dont blame about it. If something goes wrong with eclipse it might be your fault not eclipse. –  Jan 11 '12 at 07:13
  • 1
    Check this similar answer, it migth help. http://stackoverflow.com/questions/2702132/how-can-i-include-platform-specific-native-libraries-in-the-jar-file-using-ecli –  Jan 11 '12 at 07:16
  • 2
    Did you try adding project_lib/jri_native_library_folder to the manifest.mf classpath? – KJP Jan 12 '12 at 18:28
  • @KJP I am going to try that now – Julio Diaz Jan 12 '12 at 18:51
  • @KJP I didnt get any better results, I think it is because the problem is in the library path and not in the class path – Julio Diaz Jan 12 '12 at 20:09
  • What's wrong with using ANT? In the time of your running bounty, you could have written your build.xml file which does what you want. – Mot Jan 19 '12 at 05:41

4 Answers4

8

Add a script containing something like that:

#!/bin/bash
java -Djava.library.path=project_lib/native/ -jar project_lib/jri.jar

I export some java projects that way.

Ortwin Angermeier
  • 5,957
  • 2
  • 34
  • 34
3

This is relatively hard to implement. The solutions I have seen involve extracting the native libraries in the JAR to an OS temp directory and then loading it. I would go for an integrated solution for that. One Jar and Java Class Loader support it, and on the second page you will find links to similar tools.

Lucas Brutschy
  • 622
  • 4
  • 9
  • You're right, as far as I know, Java cannot load JNI libraries (.dll, .so, etc.) from a JAR file. The solutions you mention extract the relevant files at runtime, so that Java can load them. – ChrisJ Jan 19 '12 at 22:49
1

You can put the libraries inside your jar:

Export...

Java > Runnable JAR file

Package required libraries into generated Jar

Finish

I always export this way. I don't know if it will work in your case, but worth a try.


Edit:

See these links:

My guess is that this have something to do with LD_LIBRARY_PATH not correctly been set. Or the file wich it is searching for isn't in the path listed.

falsarella
  • 12,217
  • 9
  • 69
  • 115
  • I have tried that but it doesnt work, remember that the native libraries for the external package is in a folder and the java.library.path need to have access to it. – Julio Diaz Jan 13 '12 at 16:23
0

You know I had the similar problems

Could not extract native JNI library.

all above proposes can't help me. I couldn't stop and start gradle deamon by using follow command:

gradle --stop

I saw that gradle deamon still not stopped in my processes. That's why I kill it in my process and all will be fine :)

Dmytro Melnychuk
  • 2,285
  • 21
  • 23