🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java.programmer
Article #672

JNI program example, need urgent help

#672
From: Juan Pedro Barbancho Manchon
Date: Wed, 21 Jan 1998 00:00
102 lines
3533 bytes
Dear sir,
I use the JNI sun example, It compile and build a .exe, but no run well.

The code:


////////////////////INVOKE.C///////////////////
/* * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.

*
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL purposes and without
 * fee is hereby granted provided that this copyright notice
 * appears in all copies. Please refer to the file "copyright.html"
 * for further important copyright and licensing information. *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */
#include <jni.h>
main()
    {
    JNIEnv *env;
    JavaVM *jvm;
    JDK1_1InitArgs vm_args;
    jint res;
    jclass cls;
    jmethodID mid;
    jstring jstr;
    jobjectArray args;
    /* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and
beyond */
    vm_args.version = 0x00010001;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
    res = JNI_CreateJavaVM(&jvm,&env,&vm_args);
        if (res < 0) {
        fprintf(stderr, "Can't create Java VM\n");
        exit(1);
        }
    cls = (*env)->FindClass(env, "Prog.class");
        if (cls == 0) {
        fprintf(stderr, "Can't find Prog class\n");
        exit(1);
        }
    mid = (*env)->GetStaticMethodID(env, cls, "main",
"([Ljava/lang/String;)V");
    if (mid == 0) {
     fprintf(stderr, "Can't find Prog.main\n");
        exit(1);
        }
    jstr = (*env)->NewStringUTF(env, " from C!");
    if (jstr == 0) {
     fprintf(stderr, "Out of memory\n");
  exit(1);
     }
    args = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env,
"java/lang/String"), jstr);
    if (args == 0) {
     fprintf(stderr, "Out of memory\n");
  exit(1);
     }
    (*env)->CallStaticVoidMethod(env, cls, mid, args);
    (*jvm)->DestroyJavaVM(jvm);
}

The Java program:

//////////////////////////PROG.JAVA////////////////////////////////

public class Prog {
 public static void main(String[] args) {
  System.out.println("Hello World");
 }
}



The error:

can't fing Prog class

The . is in the classpath, Prog.class is in . directory.


Please, send me faster, Thank you

mail: ct2bamaj@uco.es

JuanP
--
--------------------------------------------------
Nombre y apelllidos:
Juan Pedro Barbancho Manch�n
Organizaci�n:
CTI
http://www.uco.es/grupos/cti
E-mail:
ct2bamaj@uco.es
Java Senior Programmer
Technical Details
Message-ID: <34C5CC4E.5D6E16FC@uco.es>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10a146,4658fe8c72f49849,start
X-Google-Attributes: gid10a146,public
X-Google-Thread: 113ae9,4658fe8c72f49849,start
X-Google-Attributes: gid113ae9,public
X-Google-Thread: 1116f3,4658fe8c72f49849,start
X-Google-Attributes: gid1116f3,public
From: Juan Pedro Barbancho Manchon <ct2bamaj@uco.es>
Subject: JNI program example, need urgent help
Date: 1998/01/21
Message-ID: <34C5CC4E.5D6E16FC@uco.es>
X-Deja-AN: 318001112
Content-Transfer-Encoding: 8bit
To: ANAYA <java@anaya.es>
X-Priority: 3 (Normal)
Content-Type: text/plain; charset=iso-8859-1
Organization: CTI
Mime-Version: 1.0
Newsgroups: comp.lang.java.programmer,comp.lang.java.help,es.comp.lenguajes.java