假设工程目录下有bin文件夹,bin存放编译好的class文件;
在bin目录下,
E:\eclipse\workspace\testjni\bin>javah -classpath . -jnicom.gnetis.tang.agent.ICMSAgent
然后在E:\eclipse\workspace\testjni\bin即可找到一个com.gnetis.tang.agent_jni_ICMSAgent.h头文件,生成成功!
java 文件
public class CMSException extends Exception
{
/**
*
*/
private static final long serialVersionUID = 1L;
public String codeID;
public String msg;
private String message;
public CMSException(){
}
public CMSException(String msg){
String[] strArr = msg.split("=", 2);
this.message = msg;
this.codeID = strArr[0];
this.msg = strArr[1];
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getCodeID() {
return codeID;
}
public void setCodeID(String codeID) {
this.codeID = codeID;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
package com.gnetis.tang.agent;package com.gnetis.tang.agent.excep;
import com.gnetis.tang.agent.excep.CMSException; /** * * JNI 本地调用方式 */ public class ICMSAgent { static { try{ System.out.println("load cmsagent start!!!!!!!"); System.loadLibrary("cmsagent"); System.out.println("load cmsagent end!!!!!!!"); }catch(Exception e){ e.printStackTrace(); System.out.println("load cmsagnet lib failure!!!!!!"); } } public ICMSAgent() {} // 初始化 public native int agentInit(); // 销毁 public native int agentDestroy(); // 向服务器请求关闭某种业务 public native int stopService(int site, int confID, int serviceType) throws CMSException; } public void test() { int confID = 88776655; int site = 1; // agent初始化 agentInit(); int ret; try { ret = stopService(site, confID,0x307); if (ret != 0) { System.out.println("start conference without user"); } } catch (Exception e) { e.printStackTrace(); } // agent销毁 agentDestroy(); }