网站建设朝阳,最新网页游戏排行榜2021,潍坊网站开发招聘信息,业务推广公司由于系统运行在Linux环境中#xff0c;该License绑定服务器的cpuid和mac等信息#xff0c;而java实现起来不太方便所以就利用了JNI问题及解决方法#xff1a;1、System.loadLibrary(License);时出错解决#xff1a;libLicense.so文件要放到正确的目录下#x…由于系统运行在Linux环境中该License绑定服务器的cpuid和mac等信息而java实现起来不太方便所以就利用了JNI问题及解决方法1、System.loadLibrary(License);时出错解决libLicense.so文件要放到正确的目录下可以利用System.getProperty(java.library.path));打印出path,我放的是 /lib/ 下面2、verifylicense 本地方法找不到解决头文件和C的JNIEXPORT 定义的方法名要正确包含License.java的包名如果Java中定义的method有划线的话头文件中下划线后面要紧跟一个13、加载文件和方法都没有问题运行的时候没有执行解决这个问题困扰了我一段时间最后发现安装环境时加了一个文件/etc/profile而这个文件里面没有声明CATALINA_HOME、CATALINA_BASE并且CLASSPATH里面没有带上servlet-api.jar包所以native方法无法在servlet容器中执行部分代码1、web.xmlclassjava namecodelicensecom.blingtel.common.util.License12、License.javapackage 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 [版本号, 2013-7-5]* see [相关类/方法]* since [产品/模块版本]*/public class License extends HttpServlet{/*** 注释内容*/private static final long serialVersionUID 1L;/*** 日志对象*/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 blocklogger.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 blocke1.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 blocke1.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 blocke.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 __cplusplusextern C {#endif/** Class: License* Method: verify_license* Signature: ()Z*/JNIEXPORT jboolean JNICALL Java_com_blingtel_common_util_License_verifylicense(JNIEnv *, jobject);#ifdef __cplusplus}#endif#endif4、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 __cplusplusextern C {#endifJNIEXPORT jboolean JNICALL Java_com_blingtel_common_util_License_verifylicense (JNIEnv * env, jobject job){return verify_license();}#ifdef __cplusplus}#endif