| JNI with Eclipse [message #152399] | 
Mon, 05 April 2004 13:02   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
I have a project that was originally written using Metrowerks 
CodeWarrior that uses JNI, however the  
same code built with Eclipse results in java.lang.UnsatisfiedLinkError 
exceptions. Is there anything  
unique to the Eclipse environment that is required when accessing native 
libaries via JNI? 
 
Bob
 |  
 |  
  | 
 | 
 | 
 | 
| Re: JNI with Eclipse [message #152764 is a reply to message #152723] | 
Tue, 06 April 2004 13:11    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Sam, 
 
   This is positively, absolutely NOT a source issue, but here you go. The 
ONLY difference between the  
CW version that works and this code is that Eclipse will not permit me to 
place MyNativeAPI.java in the  
default package. The CW version of MyNativeAPI.java is in the default 
package. 
 
jni generated .h file: 
 
/* DO NOT EDIT THIS FILE - it is machine generated */ 
#include <jni.h> 
/* Header for class MyNativeAPI */ 
 
#ifndef _Included_ MyNativeAPI 
#define _Included_ MyNativeAPI 
#ifdef __cplusplus 
extern "C" { 
#endif 
/* 
 * Class:     MyNativeAPI 
 * Method:    MyJNI_Open 
 * Signature: ([J)J 
 */ 
JNIEXPORT jlong JNICALL Java_ MyNativeAPI_MyJNI_1Open 
  (JNIEnv *, jobject, jlongArray); 
 
#ifdef __cplusplus 
} 
#endif 
#endif 
 
MyNativeAPI.java: 
 
package com.dog.cat;              // changed to protect the innocent, not 
present in the CW version 
public class MyNativeAPI { 
 
	public MyNativeAPI() { 
	}	 
 
    /** 
     * Native Open 
	 */ 
	public native long MyJNI_Open(long api[]); 
} 
 
native .c code 
 
#include <jni.h> 
#include "MyNativeAPI.h" 
 
#include <stdio.h> 
 
/* 
 * Class:     MyNativeAPI 
 * Method:    MyJNI_Open 
 * Signature: ([J)J 
 */ 
JNIEXPORT jlong JNICALL Java_MyNativeAPI_MyJNI_1Open( 
	JNIEnv *env, jobject jobj,  
		jlongArray japi) 
{ 
	starlic_handle_t* api; 
	starlic_error_t err; 
 
	err = my_open(&api); 
	if (err == starlic_ok) { 
		(*env)->SetLongArrayRegion(env, japi, 0, 1, (jlong*)&api); 
	} 
 
	return (jlong)err; 
} 
 
Sam Mesh wrote: 
 
> Bob, please send the sources (a reasonable small part of them:) 
 
> -- 
> Sam Mesh
 |  
 |  
  | 
| Re: JNI with Eclipse - solved [message #153238 is a reply to message #152399] | 
Wed, 07 April 2004 17:19   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Bob Barnes wrote: 
 
> I have a project that was originally written using Metrowerks 
> CodeWarrior that uses JNI, however the  
> same code built with Eclipse results in java.lang.UnsatisfiedLinkError 
> exceptions. Is there anything  
> unique to the Eclipse environment that is required when accessing native 
> libaries via JNI? 
 
> Bob 
 
I've resolved this and wanted to post the solution in case anyone runs 
into something similar. The CW  
version of this project had the class defining the native methods in the 
default package, however, the  
Eclipse project required this class (because it was imported by other 
classes in another package) to be  
in a named package. What I didn't realize was that running javah -jni 
required the complete package  
class name to be specified. For example, given class 
com.mycompany.dogs.Collie, you need to specify  
javah -jni com.mycompany.dogs.Collie. Seems like something javah could 
figure out on it's own;-(
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.08206 seconds