简体   繁体   English

如何使用包含共享库(.so)创建JAR文件

[英]How to create JAR file with includes shared library(.so)

For one of my project I need to call native c code to my java class . 对于我的项目之一,我需要将本地c代码调用到java class For this I made following steps. 为此,我做了以下步骤。

  1. In my java class I declared some native methods which are required for my project. 在我的java类中,我声明了我的项目所需的一些本机方法。 ie

     public native String print(String pM,int len); public native int openPrint(); 
  2. I initiated library file like below 我启动了如下的库文件

     static { System.loadLibrary("print"); } 
  3. After this I created header file with respect java code. 此后,我创建了关于Java代码的头文件。

  4. created c file and implemented above methods in c 创建c文件并在c中实现上述方法

  5. after this I generated library file ie libprint.so using ndk-build 之后,我使用ndk-build生成了库文件,即libprint.so

  6. library file is created successfully in libs->armeabi->libprint.so 库文件在libs->armeabi->libprint.so成功创建

  7. whenever I run that java application it's giving error saying that 每当我运行该Java应用程序时,都会出现错误提示

     Exception in thread "main" java.lang.UnsatisfiedLinkError: no print in java.library.path 

How do I solve this problem.? 我该如何解决这个问题。

I want to give this kind of application to other Android developers so that they can create this application without doing Native call and without creating libprint.so file 我想将这种应用程序提供给其他Android开发人员,以便他们可以创建此应用程序而无需执行本机调用并且无需创建libprint.so文件

It means I have to give my own API to application developer. 这意味着我必须将自己的API提供给应用程序开发人员。 For this I have to create JAR file. 为此,我必须创建JAR文件。 which includes java.class , libprint.so (shared library) and etc... 其中包括java.classlibprint.so (共享库)等。

How to create JAR file which includes libprint.so also.. 如何创建还包含libprint.so JAR文件。

I am doing all above stuffs in ubuntu using eclipse and open-jdk6. 我正在使用eclipse和open-jdk6在ubuntu中做以上所有工作。

In Windows if the jar use a dll, you must copy the dll to the root folder inside the jar. 在Windows中,如果jar使用dll,则必须将dll复制到jar内的根文件夹。 After that the program will find it. 之后,程序将找到它。

Try it, it maybe help you. 尝试一下,它可能会对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM