java 动态加载jni,用Java加载32或64位JNI库

In my Java application I need a JNI library which is available for 32 bit and 64 bit. I don't want to ship two different versions of my application so I want to ship the application with both libraries and the application must determine itself which library to load (foobar32.so or foobar64.so). How do I do that?

I thought about trying to load the first one and if this throws an exception then I load the second one but this sounds ugly.

Is there some system property I could check instead to determine if a 32 bit Java or a 64 bit Java is used to run my application? I know there is some os.arch property but the return value seems to be pretty unpredictable according to this answer.

So what is the best way to let the application decide if to load the 32 or 64 bit JNI library?

解决方案

Why unpredictable? You want only to detect if it is 32 bit system, and in this case it will be always x86 (of course for x86 processors), everything else means 64 bit.

Problems starts if you know that your code may be executed also on PPC or other non x86 processors. But in this case you may use ugly hack with exception driven flow control, and use try {} catch () to "detect" such situations.

IMHO os.arch will be the best solution.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值