日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

java jni linux_java jni实现linux环境下绑定硬件的License

發(fā)布時(shí)間:2023/12/1 linux 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java jni linux_java jni实现linux环境下绑定硬件的License 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

由于系統(tǒng)運(yùn)行在Linux環(huán)境中,該License綁定服務(wù)器的cpuid和mac等信息,而java實(shí)現(xiàn)起來不太方便所以就利用了JNI

問題及解決方法:

1、System.loadLibrary("License");時(shí)出錯(cuò)

解決:libLicense.so文件要放到正確的目錄下,可以利用System.getProperty("java.library.path"));打印出path,我放的是 /lib/ 下面

2、verifylicense 本地方法找不到

解決:頭文件和C的JNIEXPORT 定義的方法名要正確,包含License.java的包名,如果Java中定義的method有劃線的話,頭文件中下劃線后面要緊跟一個(gè)1

3、加載文件和方法都沒有問題,運(yùn)行的時(shí)候沒有執(zhí)行

解決:這個(gè)問題困擾了我一段時(shí)間,最后發(fā)現(xiàn)安裝環(huán)境時(shí)加了一個(gè)文件:/etc/profile,而這個(gè)文件里面沒有聲明CATALINA_HOME、CATALINA_BASE,并且CLASSPATH里面沒有帶上servlet-api.jar包,所以native方法無法在servlet容器中執(zhí)行

部分代碼:

1、web.xml

class="java" name="code">

license

com.blingtel.common.util.License

1

2、License.java

package com.xxx.common.util;

import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

/*

* 文件名稱: CheckLicense.java

* 文件描述:

* @version 1.0

* @author

*/

/**

*

*

* @author zengyouyuan

* @version [版本號(hào), 2013-7-5]

* @see [相關(guān)類/方法]

* @since [產(chǎn)品/模塊版本]

*/

public class License extends HttpServlet

{

/**

* 注釋內(nèi)容

*/

private static final long serialVersionUID = 1L;

/**

* 日志對(duì)象

*/

private static Log logger = LogFactory.getLog(License.class);

private native boolean verifylicense();

static

{

int i = 0;

try

{

logger.error("loadLibary start...");

System.loadLibrary("License");

i = 1;

logger.error("load Libary OK...");

}

catch (Exception e)

{

i = 2;

// TODO Auto-generated catch block

logger.error("load error");

e.printStackTrace();

Runtime runtime = Runtime.getRuntime();

try

{

i = 3;

logger.error("load libLicense.so error, killall java");

runtime.exec("killall java");

}

catch (Exception e1)

{

i = 4;

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

finally

{

logger.error("i = " + i);

if (i == 0)

{

Runtime runtime = Runtime.getRuntime();

try

{

logger.error("load libLicense.so error, killall java");

runtime.exec("killall java");

System.exit(0);

}

catch (Exception e1)

{

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

}

}

public void init(ServletConfig servletConfig)

throws ServletException

{

logger.error("income License.init()");

License l = new License();

if (l.verifylicense())

{

logger.error("verify_license ERROR");

Runtime runtime = Runtime.getRuntime();

try

{

logger.error("verify license failed, killall java");

runtime.exec("killall java");

System.exit(0);

}

catch (Exception e)

{

// TODO Auto-generated catch block

e.printStackTrace();

}

}

else

{

logger.error("verify license success! create ok.txt file");

logger.error("verify_license OK");

}

}

}

3、License.h

/* DO NOT EDIT THIS FILE - it is machine generated */

#include

/* Header for class License */

#ifndef _Included_License

#define _Included_License

#ifdef __cplusplus

extern "C" {

#endif

/*

* Class: License

* Method: verify_license

* Signature: ()Z

*/

JNIEXPORT jboolean JNICALL Java_com_blingtel_common_util_License_verifylicense

(JNIEnv *, jobject);

#ifdef __cplusplus

}

#endif

#endif

4、license_decrypt.c部分代碼

#include

#include

#include

#include

#include

#include "base64.h"

#include "rsa.h"

#include

#include "License.h"

#define KEY_LEN 128

#define RSA_N "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"\

"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"\

"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"\

"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"\

"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"\

"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"\

"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"\

"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

#define RSA_E "010001"

#pragma GCC push_options

#pragma GCC optimize ("O0")

int verify_license();

/* Header for class IntArray */

#ifdef __cplusplus

extern "C" {

#endif

JNIEXPORT jboolean JNICALL Java_com_blingtel_common_util_License_verifylicense (JNIEnv * env, jobject job)

{

return verify_license();

}

#ifdef __cplusplus

}

#endif

總結(jié)

以上是生活随笔為你收集整理的java jni linux_java jni实现linux环境下绑定硬件的License的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。