S
Steve
Hi
This subject has been posted and reading them has not helped me
I can call a Java Class "String" but when I try to call a Class I
created "Simple"
I cannot find it. I put the class in C:\WINNT\java\classes
I tried adding to a Jar file Steve.Jar with no luck
Does anyone have a suggestion what I can check????
Could the class be built wrong???
Thanks
Steve
I am running Windows2000, MSVC++, JDK1.4
Java Class
----------------
public class Simple {
public native int SimpleFct(int x) {
return x * 2;
}
}
H-File for class
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Simple */
#ifndef _Included_Simple
#define _Included_Simple
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Simple
* Method: SimpleFct
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_Simple_SimpleFct
(JNIEnv *, jobject, jint);
#ifdef __cplusplus
}
#endif
#endif
C++ Code
---------------
#include "stdafx.h"
#include "C:\JBuilder9\jdk1.4\include\jni.h"
#include "SimpleJ.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
long result;
JavaVM* jvm;
JNIEnv* env;
JavaVMInitArgs vm_args;
JavaVMOption options[4];
/* disable JIT */
options[0].optionString = "-Djava.compiler=NONE";
/* user classes */
options[1].optionString = "-Djava.class.path=C:\\WINNT\\java\\classes";
options[3].optionString =
"-Djava.library.path=C:\\JBuilder9\\jdk1.4\\lib,C:\\JBuilder9\\jdk1.4\\jre\\lib";
/* set native library path */
/* print JNI msgs */
options[2].optionString = "-verbose:jni";
vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
vm_args.nOptions = 4;
vm_args.ignoreUnrecognized = JNI_TRUE;
if ( result = JNI_GetDefaultJavaVMInitArgs( &vm_args ) )
{
// handle error
MessageBox(NULL, "Error Intir Args", "JAVA VM", MB_OK);
return -1;
}
/* Note that in the Java 2 SDK, there is no longer any need to call
* JNI_GetDefaultJavaVMInitArgs.
*/
result = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
if (result < 0)
{
MessageBox(NULL, "Error Create JAVAVM", "JAVA VM", MB_OK);
return -1;
}
else
{
MessageBox(NULL, "Sucess Create JAVAVM", "JAVA VM", MB_OK);
}
/* Find Main.main */
jclass cls2 = env->FindClass("java/lang/String");
if (cls2 == 0)
{
MessageBox(NULL, "This class not found", "JAVA VM", MB_OK);
return(1);
}
jclass cls = env->FindClass("Simple");
//jclass cls = env->FindClass("Steve/Simple"); //Try with JAR
if (cls == 0)
{
MessageBox(NULL, "This class not found", "JAVA VM", MB_OK);
return(1);
}
This subject has been posted and reading them has not helped me
I can call a Java Class "String" but when I try to call a Class I
created "Simple"
I cannot find it. I put the class in C:\WINNT\java\classes
I tried adding to a Jar file Steve.Jar with no luck
Does anyone have a suggestion what I can check????
Could the class be built wrong???
Thanks
Steve
I am running Windows2000, MSVC++, JDK1.4
Java Class
----------------
public class Simple {
public native int SimpleFct(int x) {
return x * 2;
}
}
H-File for class
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Simple */
#ifndef _Included_Simple
#define _Included_Simple
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Simple
* Method: SimpleFct
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_Simple_SimpleFct
(JNIEnv *, jobject, jint);
#ifdef __cplusplus
}
#endif
#endif
C++ Code
---------------
#include "stdafx.h"
#include "C:\JBuilder9\jdk1.4\include\jni.h"
#include "SimpleJ.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
long result;
JavaVM* jvm;
JNIEnv* env;
JavaVMInitArgs vm_args;
JavaVMOption options[4];
/* disable JIT */
options[0].optionString = "-Djava.compiler=NONE";
/* user classes */
options[1].optionString = "-Djava.class.path=C:\\WINNT\\java\\classes";
options[3].optionString =
"-Djava.library.path=C:\\JBuilder9\\jdk1.4\\lib,C:\\JBuilder9\\jdk1.4\\jre\\lib";
/* set native library path */
/* print JNI msgs */
options[2].optionString = "-verbose:jni";
vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
vm_args.nOptions = 4;
vm_args.ignoreUnrecognized = JNI_TRUE;
if ( result = JNI_GetDefaultJavaVMInitArgs( &vm_args ) )
{
// handle error
MessageBox(NULL, "Error Intir Args", "JAVA VM", MB_OK);
return -1;
}
/* Note that in the Java 2 SDK, there is no longer any need to call
* JNI_GetDefaultJavaVMInitArgs.
*/
result = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
if (result < 0)
{
MessageBox(NULL, "Error Create JAVAVM", "JAVA VM", MB_OK);
return -1;
}
else
{
MessageBox(NULL, "Sucess Create JAVAVM", "JAVA VM", MB_OK);
}
/* Find Main.main */
jclass cls2 = env->FindClass("java/lang/String");
if (cls2 == 0)
{
MessageBox(NULL, "This class not found", "JAVA VM", MB_OK);
return(1);
}
jclass cls = env->FindClass("Simple");
//jclass cls = env->FindClass("Steve/Simple"); //Try with JAR
if (cls == 0)
{
MessageBox(NULL, "This class not found", "JAVA VM", MB_OK);
return(1);
}