|
> Should I create a header file and a .so file linking
> Java and C libraries to run this?
No, you don't need to create a header file, nor is there any need to create a shared library (.so) file.
The first message says that the function `JNI_CreateJavaVM' is undefined. This probably means you're not linking with the library that contains the definition (presumably `libjvm'). It may be located in another place than on my system. Just have a look around and/or use `find' (look for `libjvm*.so').
Linking with an object file created from FORTRAN code shouldn't be too difficult. You just need to compile it separately from the C program and declare function in the latter, specifying "FORTRAN" linkage, i.e., including "Fortran" or "FORTRAN" in the declaration. I've never actually done this, but only read how to do it, and I don't remember the exact syntax. A quick search in the internet or the GCC manual should tell you how to do this.
Then, link the object files. In the example I gave, I compiled and linked in one step, but it's not any more difficult to compile and link in two steps. The `-I' and `-L' options are needed for compiling and the `-l' option for linking.
> CTest.o eh_frame+0x12): undefined reference to
> `__gxx_personality_v0'
I don't know what this is about. I believe it has something to do with the fact that GCC is used to compile various languages, so one back-end has various "personalities", i.e., one for FORTRAN, one for Pascal, etc. gxx is for C++. C++ is a bit different, because a C++ compiler (and linker) must do considerably more compilicated things than a compiler and linker for C, Fortran or Pascal. Are you sure gxx is installed? Does it work to compile a trivial C++ program?
Otherwise, it's possible that this error might have something to do with the first one, and if you correct that one, this error might disappear. Otherwise, I'd try searching the internet to see if this error has been discussed somewhere.
I hope this helps.
Laurence
|
|
|
|
|
CTest.o eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
It just occurred to me that I've had a similar error message when the compiler couldn't tell from the extension of the filename whether it was C or C++. In this case, I would expect it to recognize that `.cpp' should be C++, but it wouldn't do any harm to change it to `.cxx' or use the `-x <language>' option, i.e., `-x c++'.
Laurence
|
|
|
|
|
Your article gave me some ideas to fix my code, which I was struggling with for several hours already.
|
|
|
|
|
i have build a c++ dll via visual studio 2005, which i call by a jar-file and it works perfect on my computer also having the files on a usb-stick.
i tried several other computers and usually i get the message " main class not found ", which i suppose happens because the loading of the dll fails.
I´m not a professional programmer, but i´m quite sure the problem is connected with visual studio. the only other maschine my jar and dll worked was also equipped with visual studio.
there are loads of settings in the vc-project properties, which are hard for me to understand.
does anyone know, what is the problem and help me out.
|
|
|
|
|
sorry, this was trivial. i just had to run the code in vs in release and not in debug mode.
|
|
|
|
|
I have resolved all errors by adding addition library & include files.
Application is compiling without errors but after execution it crashes while
making a call to JNI_CreateJavaVM function.
Please help me on urgent basis.
|
|
|
|
|
Could you please post the details of version of JDK and your working environment.
Also post the changes you made in the code.
Regards,
Qarshi
|
|
|
|
|
I placed my exe in same directory where jvm.dll is (C:\Program Files\Java\jdk1.6.0\jre\bin\client), now it is working.Y it is not working when i put the jvm.dll in my debug folder.?
Can u please also guide me how can i call my class & methods from .jar file.
|
|
|
|
|
Please add the jvm.dll file path in your environment variable (i.e. PATH ).
The reason now its working is because it found the jvm.dll file in the working folder.
All the executables (On Windows) search for some required library in following order:
The directory from which the application loaded. i.e. the Working folder.
The system directory.
The Windows directory.
The directories that are listed in the PATH environment variable.
As far as calling the class methods from a .jar method is concerned, yes you can. I haven't tried it personally but I am sure you can.
After making a .jar file execute the following command to see the contents of the jar file. Now while calling the FindClass function pass the path found the contents of following command:
jar tvf MyJar.jar
Suppose the path found for your class in the above jar file is "org/MyLibs/MyClass.class"
When you will be calling a FindClass function do as below:
(*env)->FindClass("org/MyLibs/MyClass");
I haven't tested it because I don't have any C compiler on my machine. So hopefully it will help.
Regards,
Ahmad Qarshi
|
|
|
|
|
Thankyou for all of your support.
We have a method in our java class with following signature
void SomeMethod(int systemId,set < java.io.file > files,int prefPos)
Can u please guide us how can we pass set < java.io.file > files parameter from c++ to java method.modified on Wednesday, February 24, 2010 8:42 AM
|
|
|
|
|
Hi,
I tried with this example, But i am getting same issue. If i copy C exe in JDK Folder it works else it raise Exception JVM initilisation error.
I read the above thread and try setting environment veriables but same results.
Can you please help me out in understanding the
The directory from which the application loaded. i.e. the Working folder.
The system directory.
The Windows directory.
The directories that are listed in the PATH environment variable.
Where and what need to set.
I am using Visual studio 2005 VC++ Compiler professional edition.
Saurabh Vashistha
|
|
|
|
|
hi friend,
I am facing problem to call Java method from C++ project.
JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption options;
options.optionString = "-Djava.class.path=D:\\Java Src\\TestStruct";
vm_args.version = JNI_VERSION_1_6;
vm_args.nOptions = 1;
vm_args.options = &options;
vm_args.ignoreUnrecognized = 0;
int ret = JNI_CreateJavaVM(jvm, (void**)&env, &vm_args); ///////Stop from here when running C++ proj.... what to do ???
if(ret < 0)
printf("\nUnable to Launch JVM\n");
return env;
Need help...... plz
|
|
|
|
|
(Solution is at the end of the article)
Hi,
first of all thank you for your effort to write this article.
I'm glad I found this one because it seems that not many articles
about this theme exist in the internet
I do have some third party java code which I'd like to include in
my cpp project so your example hits the problem very good.
Compiling your example however I get the following error message:
-------------------------------------------------------------
Error occurred during initialization of VM
Unable to load native library: Can't find dependent libraries
-------------------------------------------------------------
I did configure the options.optionString correctly.
What do you mean by:
#define USER_CLASSPATH "." /* where Prog.class is */
Do I have to adapt this somehow?
Thank you for your help!
Bye bye,
Roland
Bye the way, I'm using
- jdk1.6.0_18 and
- Microsoft Visual C++ 6.0 as you did in your example under
- Windows Vista XP Professional Version 2002 Service Pack 3
### Solution ###
So, the solution was to set "C:\Program Files\Java\jdk1.6.0_18\jre\bin\client"
in the PATH environment variable
Again, thank you for your article!!!
modified on Friday, January 29, 2010 9:16 AM
|
|
|
|
|
I m trying to run the given program but one error comes that is
c:\users\mohd\documents\visual studio 2008\projects\ctest\ctest.cpp(3) : fatal error C1083: Cannot open include file: 'jni.h': No such file or directory
the jni.h file is not found
please help me to sort out this problem...
tnx in advance...
modified on Tuesday, January 26, 2010 11:18 PM
|
|
|
|
|
HI,
Add the C:\Java\jdk1.6.0_18\include and C:\Java\jdk1.6.0_18\include\win32 in the "Additional Include Directories" of your project properties under C/C++\General.
Also add the jvm.lib to the additional libraries.
|
|
|
|
|
hi friend ... I got a compile time error. its saying ....
/tmp/cc06USvM.o: In function `create_vm':
CTest.c text+0x3a): undefined reference to `JNI_CreateJavaVM'
collect2: ld returned 1 exit status
I am using your c version code(after making the suggested change ).
even for c++ code ... getting similar type of error. This is what i am getting in c++ ...
/tmp/cc1Vr5Ol.o: In function `create_vm(JavaVM_**)':
CTest.cpp text+0x3a): undefined reference to `JNI_CreateJavaVM'
/tmp/cc1Vr5Ol.o eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
I have jdk1.6.0_18. I compile the code with given command in linux os.
gcc -I /usr/java/jdk1.6.0_18/include -I /usr/java/jdk1.6.0_18/include/linux CTest.c
here is the modified code ......
#include "StdAfx.h"
#include <stdio.h>
#include "jni.h"
#include <string.h>
#define PATH_SEPARATOR ';' /* define it to be ':' on Solaris */
#define USER_CLASSPATH "." /* where Prog.class is */
struct ControlDetail
{
int ID;
char Name[100];
char IP[100];
int Port;
};
struct WorkOrder
{
char sumSerialId[20];
char accessNumber[18];
char actionType[4];
char effectiveDate[24];
char fetchFlag[2];
char reason[456];
char accessSource[100];
};
JNIEnv* create_vm(JavaVM ** jvm) {
JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption options;
// options.optionString = "-Djava.class.path=D:\\Java Src\\TestStruct"; //Path to the java source code
options.optionString = "-Djava.class.path=/home/mukesh/c_room/Java Src/TestStruct"; //Path to the java source code
vm_args.version = JNI_VERSION_1_6; //JDK version. This indicates version 1.6
vm_args.nOptions = 1;
vm_args.options = &options;
vm_args.ignoreUnrecognized = 0;
int ret = JNI_CreateJavaVM(jvm, (void**)&env, &vm_args);
if(ret < 0)
printf("\nUnable to Launch JVM\n");
return env;
}
int main(int argc, char* argv[])
{
JNIEnv *env;
JavaVM * jvm;
env = create_vm(&jvm);
if (env == NULL)
return 1;
struct ControlDetail ctrlDetail;
ctrlDetail.ID = 11;
strcpy(ctrlDetail.Name,"HR-HW");
strcpy(ctrlDetail.IP,"10.32.164.133");
ctrlDetail.Port = 9099;
printf("Struct Created in C has values:\nID:%d\nName:%s\n IP:%s\nPort:%d\n",ctrlDetail.ID,ctrlDetail.Name,ctrlDetail.IP,ctrlDetail.Port);
/********************************************************/
struct WorkOrder WO[2];
strcpy(WO[0].sumSerialId,"2000");
strcpy(WO[0].accessNumber,"2878430");
strcpy(WO[0].actionType,"04");
strcpy(WO[0].effectiveDate,"25-12-2007 12:20:30 PM");
strcpy(WO[0].fetchFlag, "0");
strcpy(WO[0].reason,"Executed Successfully");
strcpy(WO[0].accessSource,"PMS");
strcpy(WO[1].sumSerialId,"1000");
strcpy(WO[1].accessNumber,"2878000");
strcpy(WO[1].actionType,"T4");
strcpy(WO[1].effectiveDate,"25-12-2007 11:20:30 PM");
strcpy(WO[1].fetchFlag,"0");
strcpy(WO[1].reason,"");
strcpy(WO[1].accessSource,"RMS");
jclass clsH=NULL;
jclass clsC = NULL;
jclass clsW = NULL;
jclass clsR = NULL;
jmethodID midMain = NULL;
jmethodID midCalling = NULL;
jmethodID midDispStruct = NULL;
jmethodID midDispStructArr = NULL;
jmethodID midRetObjFunc = NULL;
jmethodID midCtrlDetConst = NULL;
jmethodID midWoConst = NULL;
jobject jobjDet = NULL;
jobject jobjRetData = NULL;
jobjectArray jobjWOArr = NULL;
//Obtaining Classes
clsH = (*env)->FindClass(env, "HelloWorld");
clsC = (*env)->FindClass(env, "ControlDetail");
clsW = (*env)->FindClass(env, "WorkOrder");
//Obtaining Method IDs
if (clsH != NULL)
{
midMain = (*env)->GetStaticMethodID(env, clsH, "main", "([Ljava/lang/String;)V");
midCalling = (*env)->GetStaticMethodID(env, clsH,"TestCall","(Ljava/lang/String;)V");
midDispStruct = (*env)->GetStaticMethodID(env, clsH,"DisplayStruct","(LControlDetail;)I");
midDispStructArr = (*env)->GetStaticMethodID(env, clsH,"DisplayStructArray","([LWorkOrder;)V");
midRetObjFunc = (*env)->GetStaticMethodID(env, clsH,"ReturnObjFunc","()Ljava/lang/Object;");
}
else
{
printf("\nUnable to find the requested class\n");
}
if(clsC != NULL)
{
//Get constructor ID for ControlDetail
midCtrlDetConst = (*env)->GetMethodID(env, clsC, "<init>", "(ILjava/lang/String;Ljava/lang/String;I)V");
}
else
{
printf("\nUnable to find the requested class\n");
}
if(clsW != NULL)
{
//Get Constructor ID for WorkOrder
midWoConst = (*env)->GetMethodID(env, clsW, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
}
else
{
printf("\nUnable to find the requested class\n");
}
/************************************************************************/
/* Now we will call the functions using the their method IDs */
/************************************************************************/
if(midMain != NULL)
(*env)->CallStaticVoidMethod(env, clsH, midMain, NULL); //Calling the main method.
if (midCalling!=NULL)
{
jstring StringArg = (*env)->NewStringUTF(env, "\nTestCall:Called from the C Program\n");
//Calling another static method and passing string type parameter
(*env)->CallStaticVoidMethod(env, clsH,midCalling,StringArg);
}
printf("\nGoing to Call DisplayStruct\n");
if (midDispStruct!=NULL)
{
if(clsC != NULL && midCtrlDetConst != NULL)
{
jstring StringArgName = (*env)->NewStringUTF(env, ctrlDetail.Name);
jstring StringArgIP = (*env)->NewStringUTF(env, ctrlDetail.IP);
//Creating the Object of ControlDetail.
jobjDet = (*env)->NewObject(env, clsC, midCtrlDetConst, (jint)ctrlDetail.ID, StringArgName, StringArgIP, (jint)ctrlDetail.Port);
}
if(jobjDet != NULL && midDispStruct != NULL)
(*env)->CallStaticIntMethod(env, clsH,midDispStruct,jobjDet); //Calling the method and passing ControlDetail Object as parameter
}
//Calling a function from java and passing Structure array to it.
printf("\n\nGoing to call DisplayStructArray From C\n\n");
if (midDispStructArr!=NULL)
{
if(clsW != NULL && midWoConst != NULL)
{
//Creating the Object Array that will contain 2 structures.
jobjWOArr = (jobjectArray)(*env)->NewObjectArray(env, 2,clsW,
(*env)->NewObject(env, clsW, midWoConst,
(*env)->NewStringUTF(env, ""),
(*env)->NewStringUTF(env, ""),
(*env)->NewStringUTF(env, ""),
(*env)->NewStringUTF(env, ""),
(*env)->NewStringUTF(env, ""),
(*env)->NewStringUTF(env, ""),
(*env)->NewStringUTF(env, "")));
//Initializing the Array
int i = 0;
for(i=0;i<2;i++)
{
(*env)->SetObjectArrayElement(env, jobjWOArr,i,
(*env)->NewObject(env, clsW, midWoConst,
(*env)->NewStringUTF(env, WO[i].sumSerialId),
(*env)->NewStringUTF(env, WO[i].accessNumber),
(*env)->NewStringUTF(env, WO[i].actionType),
(*env)->NewStringUTF(env, WO[i].effectiveDate),
(*env)->NewStringUTF(env, WO[i].fetchFlag),
(*env)->NewStringUTF(env, WO[i].reason),
(*env)->NewStringUTF(env, WO[i].accessSource)));
}
}
//Calling the Static method and passing the Structure array to it.
if(jobjWOArr != NULL && midDispStructArr != NULL)
(*env)->CallStaticVoidMethod(env, clsW,midDispStructArr,jobjWOArr);
}
//Calling a Static function that return an Object
if (midRetObjFunc != NULL)
{
//Calling the function and storing the return object into jobject type variable
//Returned object is basically a structure having two fields (string and integer)
jobjRetData = (jobject)(*env)->CallStaticObjectMethod(env, clsH,midRetObjFunc,NULL);
//Get the class of object
clsR = (*env)->GetObjectClass(env, jobjRetData);
//Obtaining the Fields data from the returned object
jint nRet = (*env)->GetIntField(env, jobjRetData,(*env)->GetFieldID(env, clsR,"returnValue","I"));
jstring jstrLog = (jstring)(*env)->GetObjectField(env, jobjRetData,(*env)->GetFieldID(env, clsR,"Log","Ljava/lang/String;"));
const char *pLog = (*env)->GetStringUTFChars(env, jstrLog,0);
printf("\n\nValues Returned from Object are:\nreturnValue=%d\nLog=%s",nRet,pLog);
//After using the String type data release it.
(*env)->ReleaseStringUTFChars(env, jstrLog,pLog);
}
//Release resources.
int n = (*jvm)->DestroyJavaVM(jvm);
return 0;
}
Thanking you
Mukesh Kumar
|
|
|
|
|
Hi,
I compiled the CTest.cpp. But I got error that "unable to open StdAfx.h and jni.h ". Can any body help me?
I am attaching the Source code:
CTest.cpp
===========
#include "StdAfx.h"
#include <stdio.h>
#include <jni.h>
#include <string.h>
#define PATH_SEPARATOR ';' /* define it to be ':' on Solaris */
#define USER_CLASSPATH "." /* where Prog.class is */
struct ControlDetail
{
int ID;
char Name[100];
char IP[100];
int Port;
};
struct WorkOrder
{
char sumSerialId[20];
char accessNumber[18];
char actionType[4];
char effectiveDate[24];
char fetchFlag[2];
char reason[456];
char accessSource[100];
};
JNIEnv* create_vm(JavaVM ** jvm) {
JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption options;
options.optionString = "-Djava.class.path=D:\\Java Src\\TestStruct"; //Path to the java source code
vm_args.version = JNI_VERSION_1_5; //JDK version. This indicates version 1.5
vm_args.nOptions = 1;
vm_args.options = &options;
vm_args.ignoreUnrecognized = 0;
int ret = JNI_CreateJavaVM(jvm, (void**)&env, &vm_args);
if(ret < 0)
printf("\nUnable to Launch JVM\n");
return env;
}
int main(int argc, char* argv[])
{
JNIEnv *env;
JavaVM * jvm;
env = create_vm(&jvm);
if (env == NULL)
return 1;
struct ControlDetail ctrlDetail;
ctrlDetail.ID = 11;
strcpy(ctrlDetail.Name,"HR-HW");
strcpy(ctrlDetail.IP,"10.32.164.133");
ctrlDetail.Port = 9099;
printf("Struct Created in C has values:\nID:%d\nName:%s\n IP:%s\nPort:%d\n",ctrlDetail.ID,ctrlDetail.Name,ctrlDetail.IP,ctrlDetail.Port);
/********************************************************/
struct WorkOrder WO[2];
strcpy(WO[0].sumSerialId,"2000");
strcpy(WO[0].accessNumber,"2878430");
strcpy(WO[0].actionType,"04");
strcpy(WO[0].effectiveDate,"25-12-2007 12:20:30 PM");
strcpy(WO[0].fetchFlag, "0");
strcpy(WO[0].reason,"Executed Successfully");
strcpy(WO[0].accessSource,"PMS");
strcpy(WO[1].sumSerialId,"1000");
strcpy(WO[1].accessNumber,"2878000");
strcpy(WO[1].actionType,"T4");
strcpy(WO[1].effectiveDate,"25-12-2007 11:20:30 PM");
strcpy(WO[1].fetchFlag,"0");
strcpy(WO[1].reason,"");
strcpy(WO[1].accessSource,"RMS");
jclass clsH=NULL;
jclass clsC = NULL;
jclass clsW = NULL;
jclass clsR = NULL;
jmethodID midMain = NULL;
jmethodID midCalling = NULL;
jmethodID midDispStruct = NULL;
jmethodID midDispStructArr = NULL;
jmethodID midRetObjFunc = NULL;
jmethodID midCtrlDetConst = NULL;
jmethodID midWoConst = NULL;
jobject jobjDet = NULL;
jobject jobjRetData = NULL;
jobjectArray jobjWOArr = NULL;
//Obtaining Classes
clsH = env->FindClass("HelloWorld");
clsC = env->FindClass("ControlDetail");
clsW = env->FindClass("WorkOrder");
//Obtaining Method IDs
if (clsH != NULL)
{
midMain = env->GetStaticMethodID(clsH, "main", "([Ljava/lang/String;)V");
midCalling = env->GetStaticMethodID(clsH,"TestCall","(Ljava/lang/String;)V");
midDispStruct = env->GetStaticMethodID(clsH,"DisplayStruct","(LControlDetail;)I");
midDispStructArr = env->GetStaticMethodID(clsH,"DisplayStructArray","([LWorkOrder;)V");
midRetObjFunc = env->GetStaticMethodID(clsH,"ReturnObjFunc","()Ljava/lang/Object;");
}
else
{
printf("\nUnable to find the requested class\n");
}
if(clsC != NULL)
{
//Get constructor ID for ControlDetail
midCtrlDetConst = env->GetMethodID(clsC, "<init>", "(ILjava/lang/String;Ljava/lang/String;I)V");
}
else
{
printf("\nUnable to find the requested class\n");
}
if(clsW != NULL)
{
//Get Constructor ID for WorkOrder
midWoConst = env->GetMethodID(clsW, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
}
else
{
printf("\nUnable to find the requested class\n");
}
/************************************************************************/
/* Now we will call the functions using the their method IDs */
/************************************************************************/
if(midMain != NULL)
env->CallStaticVoidMethod(clsH, midMain, NULL); //Calling the main method.
if (midCalling!=NULL)
{
jstring StringArg = env->NewStringUTF("\nTestCall:Called from the C Program\n");
//Calling another static method and passing string type parameter
env->CallStaticVoidMethod(clsH,midCalling,StringArg);
}
printf("\nGoing to Call DisplayStruct\n");
if (midDispStruct!=NULL)
{
if(clsC != NULL && midCtrlDetConst != NULL)
{
jstring StringArgName = env->NewStringUTF(ctrlDetail.Name);
jstring StringArgIP = env->NewStringUTF(ctrlDetail.IP);
//Creating the Object of ControlDetail.
jobjDet = env->NewObject(clsC, midCtrlDetConst, (jint)ctrlDetail.ID, StringArgName, StringArgIP, (jint)ctrlDetail.Port);
}
if(jobjDet != NULL && midDispStruct != NULL)
env->CallStaticIntMethod(clsH,midDispStruct,jobjDet); //Calling the method and passing ControlDetail Object as parameter
}
//Calling a function from java and passing Structure array to it.
printf("\n\nGoing to call DisplayStructArray From C\n\n");
if (midDispStructArr!=NULL)
{
if(clsW != NULL && midWoConst != NULL)
{
//Creating the Object Array that will contain 2 structures.
jobjWOArr = (jobjectArray)env->NewObjectArray(2,clsW,env->NewObject(clsW, midWoConst,env->NewStringUTF(""),env->NewStringUTF(""),env->NewStringUTF(""),
env->NewStringUTF(""),env->NewStringUTF(""),env->NewStringUTF(""),env->NewStringUTF("")));
//Initializing the Array
for(int i=0;i<2;i++)
{
env->SetObjectArrayElement(jobjWOArr,i,env->NewObject(clsW, midWoConst,env->NewStringUTF(WO[i].sumSerialId),
env->NewStringUTF(WO[i].accessNumber),
env->NewStringUTF(WO[i].actionType),
env->NewStringUTF(WO[i].effectiveDate),
env->NewStringUTF(WO[i].fetchFlag),
env->NewStringUTF(WO[i].reason),
env->NewStringUTF(WO[i].accessSource)));
}
}
//Calling the Static method and passing the Structure array to it.
if(jobjWOArr != NULL && midDispStructArr != NULL)
env->CallStaticVoidMethod(clsW,midDispStructArr,jobjWOArr);
}
//Calling a Static function that return an Object
if (midRetObjFunc != NULL)
{
//Calling the function and storing the return object into jobject type variable
//Returned object is basically a structure having two fields (string and integer)
jobjRetData = (jobject)env->CallStaticObjectMethod(clsH,midRetObjFunc,NULL);
//Get the class of object
clsR = env->GetObjectClass(jobjRetData);
//Obtaining the Fields data from the returned object
jint nRet = env->GetIntField(jobjRetData,env->GetFieldID(clsR,"returnValue","I"));
jstring jstrLog = (jstring)env->GetObjectField(jobjRetData,env->GetFieldID(clsR,"Log","Ljava/lang/String;"));
const char *pLog = env->GetStringUTFChars(jstrLog,0);
printf("\n\nValues Returned from Object are:\nreturnValue=%d\nLog=%s",nRet,pLog);
//After using the String type data release it.
env->ReleaseStringUTFChars(jstrLog,pLog);
}
//Release resources.
int n = jvm->DestroyJavaVM();
return 0;
}
Java Codes
***********
ControlNEDetail.java
====================
public class ControlNEDetail
{
public int ID;
public String Name;
public String IP;
public int Port;
public ControlNEDetail(int nID, String szName, String szIP, int nPort)
{
this.ID = nID;
this.Name = szName;
this.IP = szIP;
this.Port = nPort;
}
}
ReturnData.java
================
public class ReturnData
{
int returnValue;
String Log;
public ReturnData(int nRetVal, String szLog)
{
this.returnValue = nRetVal;
this.Log = szLog;
}
}
WorkOrder.java
===============
public class WorkOrder
{
String sumSerialId;
String accessNumber;
String actionType;
String effectiveDate;
String fetchFlag;
String reason;
String accessSource;
public WorkOrder(String szSumID,String szAccNum, String szActType, String szEffectDate, String fetchFlg, String szReason, String szAccSrc )
{
this.sumSerialId = szSumID;
this.accessNumber = szAccNum;
this.actionType = szActType;
this.effectiveDate = szEffectDate;
this.fetchFlag = fetchFlg;
this.reason = szReason;
this.accessSource = szAccSrc;
}
};
HelloWorld.java
================
public class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello World!");
System.out.println("This is the main function in HelloWorld class");
}
public static void TestCall(String szArg)
{
System.out.println(szArg);
}
public static int DisplayStruct(ControlNEDetail ctrlDetail)
{
System.out.println("Structure is:\n-------------------------");
System.out.println("Name:" + ctrlDetail.Name);
System.out.println("IP:" + ctrlDetail.IP);
System.out.println("Port" + ctrlDetail.Port);
return 1;
}
public static void DisplayStructArray(WorkOrder ArrWO[])
{
System.out.println("WorkOrders are Given hereunder:\n----------------------------");
for(int i = 0; i< ArrWO.length;i++)
{
System.out.println("<---Work Order Number:" + String.valueOf(i+1) + "<---");
System.out.println("Sum_Serial_ID: " + ArrWO[i].sumSerialId);
System.out.println("Access_Number: " + ArrWO[i].accessNumber);
System.out.println("Action_Type: " + ArrWO[i].actionType);
System.out.println("Effective_Date: " + ArrWO[i].effectiveDate);
System.out.println("Fetch_Flag: " + ArrWO[i].fetchFlag);
System.out.println("Reason: " + ArrWO[i].reason);
System.out.println("Access_Source: " + ArrWO[i].accessSource);
}
}
public static Object ReturnObjFunc()
{
System.out.println("Going to return an object from java");
ReturnData RetData = new ReturnData(1,"Successfull function call");
return RetData;
}
}
Thanks
Chinmaya
|
|
|
|
|
You need to install the latest JDK, download from Sun
and set the path into Environment variable
|
|
|
|
|
It seems like this isn't working with VS 2008/2005. It gets compiled but not running. Doesn't even give the 'jvm.dll' error.
|
|
|
|
|
|
I get an error message saying that the application has failed to start because jvm.dll was not found.
I have tried reinstalling my JDK (which is version 1.6.0 rev 14).
Any ideas?
---
There are 10 types of people in this world: those who understand binary, and those who don't.
|
|
|
|
|
Fixed it...
I needed to add the directory containing jvm.dll to my path. In my case this was:
C:\Program Files\Java\jre6\bin\client
Hope this is helpful to someone else!
---
There are 10 types of people in this world: those who understand binary, and those who don't.
|
|
|
|
|
This is how i am compiling the code...
g++ -I/usr/jdk1.6.0/include -I/usr/jdk1.6.0/include/solaris -L/usr/jdk1.6.0/jre/bin -L/usr/jdk1.6.0/jre/lib/sparc -ljvm -ljava CTest.cpp
any help would be appreciated!!
|
|
|
|
|
I get the error Unable to load JVM with error -1 which is i think is the unknown error as written in the header file. What should I do Know?
|
|
|
|
|
I'm having the same issue. Did you resolve it?
|
|
|
|
|