[Ant]How to add .so file into a jar and use it within jar(set the java.library.path)?

若如初见. 提交于 2019-12-19 10:05:22

问题


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!

来源:https://stackoverflow.com/questions/19710836/anthow-to-add-so-file-into-a-jar-and-use-it-within-jarset-the-java-library-p

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!