Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » JNI with Eclipse
JNI with Eclipse [message #152399] Mon, 05 April 2004 17:02 Go to next message
Bob is currently offline BobFriend
Messages: 44
Registered: July 2009
Member
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 #152423 is a reply to message #152399] Mon, 05 April 2004 17:17 Go to previous messageGo to next message
Mitch Christensen is currently offline Mitch ChristensenFriend
Messages: 39
Registered: July 2009
Member
We use JNI calls to a 3rd party library and everything works fine for us.

The key to the UnsatisfiedLinkError is amlost always that one or more DLL
is not in the execution path (i.e. set the PATH environment variable to
include the DLLs).

-Mitch

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
Re: JNI with Eclipse [message #152501 is a reply to message #152423] Mon, 05 April 2004 22:11 Go to previous messageGo to next message
Bob is currently offline BobFriend
Messages: 44
Registered: July 2009
Member
Nope, definitely is finding and loading the library. The one difference in
the code that I've been able to
uncover is that in the CW version of the source the java class containing
the native methods was in the
default package, while the class calling it was in it's own package.
Because of Eclipse's insistence on
folder structures matching package naming and the inability to import from
the default package
necessitated changing the package structure. Now both the class containing
the native methods and
the class calling those methods are in the sam epackage, but as far as I
can tell that shouldn't matter.
It certainly doesn't cause the generated .h file to be any differnt.

Mitch Christensen wrote:

> We use JNI calls to a 3rd party library and everything works fine for us.

> The key to the UnsatisfiedLinkError is amlost always that one or more DLL
> is not in the execution path (i.e. set the PATH environment variable to
> include the DLLs).

> -Mitch

> 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
Re: JNI with Eclipse [message #152723 is a reply to message #152501] Tue, 06 April 2004 15:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: smesh.openrules.com

Bob, please send the sources (a reasonable small part of them:)

--
Sam Mesh
Re: JNI with Eclipse [message #152764 is a reply to message #152723] Tue, 06 April 2004 17:11 Go to previous messageGo to next message
Bob is currently offline BobFriend
Messages: 44
Registered: July 2009
Member
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 21:19 Go to previous message
Bob is currently offline BobFriend
Messages: 44
Registered: July 2009
Member
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;-(
Previous Topic:JUnit launch configurations
Next Topic:Tab alignment with Eclipse M8
Goto Forum:
  


Current Time: Sat Jul 27 16:13:37 GMT 2024

Powered by FUDForum. Page generated in 0.03205 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top