执行本机方法 [英] executing the native method

查看:94
本文介绍了执行本机方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,每个人

我已经开发了一个名为A的Java类,它使用另一个名为B的类,它们都在com.kkp包中,
B类具有一些在B.cpp& B.h
我已使用g ++编译cpp文件并创建dll(B.dll).
直到这里一切都OK,程序运行正常.
我创建了一个jar文件,然后将B.dll,B.class和A.class放入其中,

jar的流(我的库)是:
将A类称为主应用程序,然后调用B类方法,而本机方法将导致执行B.dll函数(C ++ dll)以支持在外部硬件(某种打印机)上工作.

jar文件也执行正常,没问题
jar文件清单是

Hi, every body

i have developed a java class named A that uses another class named B , both of them is in package com.kkp ,
the class B have some native methods that implemented in B.cpp & B.h
i have used g++ for compiling the cpp file and creating a dll (B.dll).
til here every things is OK and program works fine .
i have create a jar file and the i put the B.dll, B.class and A.class in it,

the flow of jar (my library) is :
Class A be called form main application and then it calls class B methods and the native methods cause execution of B.dll functions (C++ dll) to support working on external hardware (some kind of printers).

the jar file also executes OK and no problem
the jar file manifest is

Main-Class: com/kkp/A
Name: com/kkp/
Sealed: true



但是我的问题是,另一个应用程序将jar文件作为库加载,并希望执行侧类A中的功能,在这种状态下,运行时错误( UnSatisfiedLinkError )出现.我知道此错误基本上是因为B类计数在此代码中找不到B.dll



but my problem is where another application load the jar file as library and wants to execute the functions in side class A , in this state a run-time error (UnSatisfiedLinkError) appears . i know that this error basically is because the class B count not find the B.dll in this code

System.loadLibrary("B");



我想将jar文件放在应用程序的Lib文件夹中.
当我将jar和B.dll放入Lib文件夹中时,会在运行时出现 UnSatisfiedLinkError ,但是当我将B.dll放入应用程序的根目录时,它可以正常运行,并且没有运行时错误发生.


我的问题是我必须做什么?,我的意思是jar文件必须放在Lib文件夹中,但B.dll必须在哪里? (我不想将dll放在应用程序目录的根目录中)

我知道这个问题可能很简单,因为我在Java编程方面有一些经验



i want to put my jar file in Lib folder of my application.
when i put the jar and B.dll in Lib folder the UnSatisfiedLinkError occurs in run-time but when i put the B.dll in root directory of application it works OK and no run-time error occurs.


my question is what i must do ?, i mean that the jar file must put in Lib folder but where the B.dll must be ? (i don''t want to put the dll in root of application''s directory)

i know this question is maybe so simple because i have a few experience in java programming

thanks in advance.

推荐答案

如果默认目录中没有dll,则应将完整路径添加到System.loadLibrary()调用中.
If you do not have the dll in the default directory then you should add the full path to your System.loadLibrary() call.


因为您要创建一个A.dll并从A.dll调用B.dll,所以我建议您先创建B.lib并将其放入A.dll中,然后您便可以调用A&B类的功能

希望这会工作........一切顺利.......
since u want to create a A.dll and call B.dll from A.dll, so i would recommend u to jst create the B.lib and put it inside A.dll then u will be able to call the functions of both class A&B

hope this will work........All the best.......


对于System.loadLibrary()调用,dll文件应位于java的路径中即system32,但我建议System.load()代替,通过它您可以给出dll文件的完整路径,并在罐子中的任何其他Java应用程序中使用它
for the System.loadLibrary() call the dll file should be in path of java i.e system32 but i would recommend System.load() instead by which you would be able to give full path of the dll file and use it in any other java app usin that jar


这篇关于执行本机方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆