- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- calling C from java
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2009 11:50 AM
04-02-2009 11:50 AM
calling C from java
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2009 12:13 PM
04-02-2009 12:13 PM
Re: calling C from java
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2009 12:16 PM
04-02-2009 12:16 PM
Re: calling C from java
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2009 01:38 PM
04-02-2009 01:38 PM
Re: calling C from java
Calling C shouldn't be any different from Cobol or Fortran. The VMS calling standard is specifically designed to make intra language calls possible, and relatively painless.
The biggest issue is matching data types between the languages. There should be a better match for data types between Java and C, as you may not need to worry about string descriptors and packed decimal types.
Start with your existing Fortran example, and replace the Fortran routine with a C equivalent. Make sure you can receive and return all the data types you're interested in.
I'd expect far more people to be calling C from Java than Cobol. Chances are, the reason you can't find any example code is it's too easy!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2009 09:40 PM
04-02-2009 09:40 PM
Re: calling C from java
Please contact me offline and I would
be happy to provide you with few examples
that call C from Java.
Regards,
Guy Peleg
Maklee Engineering
www.maklee.com
guy.peleg@company_name.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2009 09:51 AM
04-03-2009 09:51 AM
Re: calling C from java
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2009 11:33 AM
04-03-2009 11:33 AM
Re: calling C from java
:-)
$ type y.c
#include
main() { printf("guy.peleg@%s.com","maklee"); return 1; }
$
$ cc y
$ link y
$ run y
[the answer appears here]
$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2009 02:34 PM
04-03-2009 02:34 PM
Re: calling C from java
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2009 06:58 AM
04-04-2009 06:58 AM
Re: calling C from java
you can also use SWIG, which generates the jackets routines: http://www.swig.org/
SWIG 1.3.31 has been ported on OpenVMS and I have extensively used it without any problem (but not with java...)
JF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2009 03:38 PM
04-05-2009 03:38 PM
Re: calling C from java
Guy thanks for your valuable example to give me a starting point.
SUNNY2$ type snd_snmp.java
class SYSTEMCALL {
public native int SNMPTRAP (String msg);
static {
System.loadLibrary("SNDSNMP_C");
}
public static void main (String[] args) {
System.out.println("This is java ..calling the C routing");
int result = new SYSTEMCALL().SNMPTRAP("TEST TRAP MSG");
System.out.println("for now lets omit this");
}
}
$ javac snd_snmp.java
$ javah -jni "SYSTEMCALL"
$TYPE SYSTEMCALL.H
/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class SYSTEMCALL */
#ifndef _Included_SYSTEMCALL
#define _Included_SYSTEMCALL
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: SYSTEMCALL
* Method: SNMPTRAP
* Signature: (Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_SYSTEMCALL_SNMPTRAP
(JNIEnv *, jobject, jstring);
#ifdef __cplusplus
}
#endif
#endif
SUNNY2$ type sndsnmp_c.c
#include "SYSTEMCALL.H"
#include
#include
#include
#define size 512
static char cmdbuffer[size];
/* main(int argc, char **argv ) */
JNIEXPORT jint JNICALL Java_SYSTEMCALL_SNMPTRAP
(JNIEnv *env, jobject obj , jstring cmdbuffer) {
int i;
int sts;
char *cmd = "mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.100.18.245 -v2c 1.3.6.1.6.3.1.1.4.1.0 \"D\"";
strncat (cmdbuffer, cmd,size);
strncat (cmdbuffer, " \"",size);
strncat (cmdbuffer, argv[1],size);
strncat (cmdbuffer,"\"",size);
printf ("%s\n",cmdbuffer);
sts = system(cmdbuffer);
printf( " sts = %%x%08x.\n", sts);
}
SUNNY2$
SUNNY2$ cc /prefix=all/float=ieee/ieee=denorm/defin=JIT_OPTION/names=(short,as_is)
/reent=multithread/includ=SYS$COMMON:[JAVA$142.INCLUDE...] SNDSNMP_C
SUNNY2$ cc /prefix=all/float=ieee/ieee=denorm/defin=JIT_OPTION/names=(short,as_is) /reent=multithread/includ=SYS$COMMON:[JAVA$142.
INCLUDE...] SNDSNMP_C
strncat (cmdbuffer, cmd,size);
.............^
%CC-W-PTRMISMATCH, In this statement, the referenced type of the pointer value "cmdbuffer" is "struct _jobject", which is not compat
ible with "char".
at line number 18 in file DISK$ORACLE:[ORACLE9I]SNDSNMP_C.C;18
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2009 08:38 PM
04-05-2009 08:38 PM
Re: calling C from java
You have:
static char cmdbuffer[size];
JNIEXPORT jint JNICALL Java_SYSTEMCALL_SNMPTRAP
(JNIEnv *env, jobject obj, jstring cmdbuffer) {
Your parm name cmdbuffer hides your file scope definition.
If you were using a real language like C++, you could just use ::cmdbuffer to access the global scope. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2009 10:15 PM
04-05-2009 10:15 PM
Re: calling C from java
cu,
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2009 11:58 PM
04-05-2009 11:58 PM
Re: calling C from java
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2009 07:49 AM
04-06-2009 07:49 AM
Re: calling C from java
static char cmdbuffer[size];
/* main(int argc, char **argv ) */
JNIEXPORT jint JNICALL Java_SYSTEMCALL_SNMPTRAP
(JNIEnv *env, jobject obj , jstring msg) {
int i;
int sts;
char *cmd = "mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.100.18.245 -v2c 1.3.6.1.6.3.1.1.4.1.0 \"D\"";
char buf[512];
const jbyte *str;
str = (*env)->GetStringUTFChars(env, msg, NULL);
if (str == NULL) {
return NULL; /* OutOfMemoryError already thrown */
}
printf("%s", str);
(*env)->ReleaseStringUTFChars(env, msg, str);
/* strncat (cmdbuffer, cmd,size);
strncat (cmdbuffer, " \"",size);
strncat (cmdbuffer, argv[1],size);
strncat (cmdbuffer,"\"",size);
printf ("%s\n",cmdbuffer);
sts = system(cmdbuffer);
printf( " sts = %%x%08x.\n", sts);
*/
return 0;
}
$link/share=sndsnmp_c sndsnmp_c,sndsnmp_c/opt
$ JAVA "SYSTEMCALL" "testing"
Warning: JIT compiler "SUNCOMPILER" not found. Will use interpreter.
Exception in thread "main" java.lang.UnsatisfiedLinkError: no SNDSNMP_C in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1578)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2009 07:52 AM
04-06-2009 07:52 AM
Re: calling C from java
SUNNY2$ type sndsnmp_c.opt
case_sensitive=YES
symbol_vector=(Java_SYSTEMCALL_SNMPTRAP=PROCEDURE)
case_sensitive=NO
java$java_shr/share
gsmatch=lequal,1,1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2009 08:03 AM
04-06-2009 08:03 AM
Re: calling C from java
is the function of the libgesyi logical pointing to the shared image ? I didnt define any such logical, is this the reason iam getting error? how is this logical name constructed ?
$ link/share=getjpi_shr.exe getjpi_nat.obj,getjpi.opt/opt,java.opt/opt
$ link/debug/share=getjpi_g_shr.exe getjpi_nat.obj,getjpi.opt/opt,java_g.opt/opt
$
$ define/nolog libgetsyi sys$disk:[]getsyi_shr.exe
$ define/nolog libgetsyi_g sys$disk:[]getsyi_g_shr.exe
$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2009 08:22 AM
04-06-2009 08:22 AM
Re: calling C from java
SUNNY2$ link/share/exec=java$sndsnmp_c_shr.exe sndsnmp_c,sndsnmp_c/opt
SUNNY2$ def/job/log java$sndsnmp_c_shr sys$login:java$sndsnmp_c_shr.exe
SUNNY2$ JAVA "SYSTEMCALL" "TESTING"
Warning: JIT compiler "SUNCOMPILER" not found. Will use interpreter.
This is java ..calling the C routing
@²UP²Uà `UU0lŸz;lŸz6for now lets omit this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2009 08:57 AM
04-06-2009 08:57 AM
Re: calling C from java
any ideas why iam getting those special characters instead of the string that iam inputting as parameter?
<<<
Because you're not using it?
- The jstring parameter msg is probably not UTF8 encoded. That's why I suggested GetStringChars and not GetStringUTFChars.
- The jbyte variable str is not a null-terminated C string. That's why I suggested using GetStringLength
cu,
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2009 09:07 AM
04-06-2009 09:07 AM
Re: calling C from java
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2009 09:08 AM
04-06-2009 09:08 AM
Re: calling C from java
jstring jstr;
jstr = (*env)->NewStringUTF(env, result);
if (jstr == NULL) {
fprintf(stderr, "out of memory");
return 0;
}
printf("%s","now in C routine");
printf("%s", jstr);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2009 09:12 AM
04-06-2009 09:12 AM
Re: calling C from java
i wouldnt love to make the current method work as this would open ways of interfacing.
but can you point me to a sample code using such snmp trap java calls?
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2009 10:05 AM
04-06-2009 10:05 AM
Re: calling C from java
http://www.google.com/search?q=java+send+snmp+trap
I'm sure this could be further refined.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2009 10:13 AM
04-06-2009 10:13 AM
Re: calling C from java
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2009 10:15 AM
04-06-2009 10:15 AM
Re: calling C from java
I changed the code to use Getstringchars but I am still getting the same problem, string is not being translated..
SUNNY2$ TYPE sndsnmp_c.c;
#include "SYSTEMCALL.H"
#include
#include
#include
#define size 512
static char cmdbuffer[size];
/* main(int argc, char **argv ) */
JNIEXPORT jint JNICALL Java_SYSTEMCALL_SNMPTRAP
(JNIEnv *env, jobject obj , jstring msg) {
int i;
int sts;
char *cmd = "mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.100.18.245 -v2c 1.3.6.1.6.3.1.1.4.1.0 \"D\"";
jboolean *iscopy;
jstring ret;
jint len;
const jchar *fmt;
fmt = (*env)->GetStringChars(env, msg, iscopy);
len = (*env)->GetStringLength(env, msg);
ret = (*env)->NewString(env, fmt,len);
printf("%s","now in C routine");
printf("%s", ret);
return 0;
}
SUNNY2$ java "SYSTEMCALL"
Warning: JIT compiler "SUNCOMPILER" not found. Will use interpreter.
This is java ..calling the C routing
now in C routineh²Ux²Uà `UU0lŸz;lŸz6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2009 11:12 AM
04-06-2009 11:12 AM
Re: calling C from java
jboolean *iscopy=0;
jstring ret;
jint len;
const jchar *fmt; << it wont lt me use
jstring here .
fmt = (*env)->GetStringChars(env, msg, iscopy);
len = (*env)->GetStringLength(env, msg);
printf("%d\n", len);
printf("%s\n","now in C routine");
printf("%s", fmt);
SUNNY2$ java "SYSTEMCALL"
Warning: JIT compiler "SUNCOMPILER" not found. Will use interpreter.
This is java ..calling the C routing
18 <<<<< correct string length
now in C routine
N <<<<< only the first char of msg string
which is 'NEW TEST TRAP MSGS'