Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Java JNI
I have a test case where I am trying to access the C code from my JAVA program using JNI. Steps involved are as follows :

1. A JAVA program calling the native methods :
public class RunnerClass{
	public native void win32_svc_install();
	static{
		System.loadLibrary("testDll");
                System.out.println("library loaded successfully");   
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new RunnerClass().win32_svc_install();
	}
 
}

2. Now after the [.class] file gets generated and from that corresponding [.h] file created, I put up the native method implementation inside the [.c] file.

/* DO NOT EDIT THIS FILE - it is machine generated */
//RunnerClass.h

#include <jni.h>
/* Header for class RunnerClass */
 
#ifndef _Included_RunnerClass
#define _Included_RunnerClass
#ifdef __cplusplus
extern "C" {
#endif/*
 * Class:     RunnerClass
 * Method:    nx_win32_svc_install
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_RunnerClass_win32_1svc_1install
  (JNIEnv *, jobject);#ifdef __cplusplus
}
#endif
#endif
 

The RunnerClass.c file has the implementation for the native method inside it. What exactly this method will do is call the ServiceManager of the windows to make use of it. My JAVA program needs to perform these actions.
 
Now the problem arises after the [testDll.dll] gets created. Before interpreting the JAVA code, I set the library_path for the required library(testDll) in the java.library.path.

Now when I RUN my program, my library gets loaded but it throws UnsatisfiedLinkError to the native method. The exact error is as follows :

Exception in thread "main" hello ,java.lang.UnsatisfiedLinkError: RunnerClass.parsecmdline(ILjava/lang/String;)V
at RunnerClass.win32_svc_install(Native Method)
at RunnerClass.main(MainWs.java:58)


I did a lot of research and understood by far that the exception is thrown because the program is not able to find the implementation of the native method in the library being loaded.

I have been stuck here since last three days now and really need a solution that best resolves my existing problem.

Thanks in advance!
Posted 16-Mar-13 1:32am
Ahsetau217

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 Zoltán Zörgő 99
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 16 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100