java tuxedo jni_Java通过JNI调用Tuxedo方法

如果想要一个免费,不使用Weblogic WTC JOLT,实现Java调用Tuxedo,那最容易想到的就是通过JNI,让Java执行native代码,实现对Tuxedo的调用。

环境:Suse 9  Tuxedo 8.1  Java1.4 $JAVA_HOME $TUXDIR

实现的步骤如下 编写带native方法的Java类

/**

* This is a demo class for test JNI

*

* @author STEELE

*

*/

public class Hello {

static {

try {

// "hello" means the library of native method

System.loadLibrary("hello");

} catch (UnsatisfiedLinkError e) {

System.err.println("Cannot load hello library:“n " + e.toString());

}

}

public Hello() {

}

// This is a native method without args and return

public native void SayHello();

}

2.编译为.class文件

javac Hello.java

3.生成.h文件

javah Hello

4.编写对应的C文件,我一般直接拷贝一个.h文件为.c,之后修改,感觉比较不会出错

#include

#include "atmi.h"    /* TUXEDO  Header File */

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

#include

/* Header for class Hello */

#ifndef _Included_Hello

#define _Included_Hello

#ifdef __cplusplus

extern "C" {

#endif

/*

* Class:   Hello

* Method:   SayHello

* Signature: ()V

*/

JNIEXPORT void JNICALL Java_Hello_SayHello

(JNIEnv * env, jobject arg)

{

char *sendbuf, *rcvbuf;

long sendlen, rcvlen;

int ret;

printf("THIS IS JNI Say Hello“n");

/* Attach to System/T as a Client Process */

if (tpinit((TPINIT *) NULL) == -1) {

(void) fprintf(stderr, "Tpinit failed“n");

exit(1);

}

sendlen = 32;

/* Allocate STRING buffers for the request and the reply */

if((sendbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {

(void) fprintf(stderr,"Error allocating send buffer“n");

tpterm();

exit(1);

}

if((rcvbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {

(void) fprintf(stderr,"Error allocating receive buffer“n");

tpfree(sendbuf);

tpterm();

exit(1);

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值