3

all. I'm trying to make a bundle jar containing Sigar library, which uses a .so as native support. I've zipped the Sigar into my.jar, when I run it from cmd, I have to type like this:

java -jar -Djava.library.path=~/path/to/lib/contains/so  my.jar

Yes this works, BUT I want to build a bundle jar, that, to say, contains .so into jar and use it within the jar. So my question is: how to set the java.library.path pointing to .so files within that jar. Finally, I want to make it like

java -jar my.jar (*)// hope to run it in this way

My build.xml looks like:

 27     <target name="jar" depends="compile">
 28         <mkdir dir="${jar.dir}"/>
 29         <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
 30             <zipgroupfileset dir="${lib.dir}" includes="*.jar"/>
 31             <fileset dir="${lib.dir}"  includes="*.so"/>
 32             <fileset dir="${lib.dir}" includes="*.dylib"/>
 33             <manifest>
 34                 <attribute name="Main-Class" value="${main-class}"/>
 35             </manifest>
 36         </jar>
 37     </target>

By now, I just got UnsatisfiedLink Exception when I use run it in (*) way.

And another relevant question is: how to add a file to a specific location in the jar. In above example, <fileset dir="${lib.dir}" includes="*.so"/> will put *.so in the root of jar, what if I want to change this?

Thanks in advance!

qweruiop
  • 3,156
  • 6
  • 31
  • 55
  • You can’t do that. Native libraries are loaded by the operating system and it doesn’t support loading libraries from a JAR file. All Java libraries with native code I know of will extract their bundled native library to a temporary file and load it from there. – Holger Oct 31 '13 at 16:29
  • @Holger Thanks for reply, but how does stuff like [SqliteJDBC](https://bitbucket.org/xerial/sqlite-jdbc‎) work? It uses several `.so` in its own jar. – qweruiop Nov 01 '13 at 02:26
  • As already said, they extract these `.so` files at runtime to a temporary file and load it from there. I don’t know any other way. – Holger Nov 01 '13 at 08:21
  • 1
    @Holger Thanks; At least I know what I can't do now. – qweruiop Nov 03 '13 at 10:39

0 Answers0