The Artima Developer Community
Sponsored Link

Java Answers Forum
About jni

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Zully

Posts: 1
Nickname: zuyiro
Registered: Jun, 2004

About jni Posted: Jun 15, 2004 3:49 PM
Reply to this message Reply
Advertisement
Hi. I hope you can help me.

Well. I need to convert an unsigned long int to IP. So, I use JNI. I've
put the lib*.so into the /usr/java/j2sdk*/lib/i386. Then I run it into
eclipse like default package and it works, but When I try to run it into
eclipse using package, it's to say, if I include my libraries and class into
a package the class doesn't work.

************************Jniprueba.java***********************
//package src;
public class Jniprueba {

static
{
System.loadLibrary("MiLibreria");
}

private native String convert (long num);

/*public static void main (String args[])
{
long i =3632836505L;
Jniprueba jnifunction = new Jniprueba();
String result = jnifunction.convert(i);
System.out.println("resultado: " + result);
}
*/
}

*******************Jniprueba.c************************
#include "/usr/java/j2sdk1.4.2/include/jni.h"
#include "Jniprueba.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

JNIEXPORT jstring JNICALL
Java_Jniprueba_convert
(JNIEnv *jenv, jobject job, jint jnum){

char x[20];
strncpy(x, inet_ntoa(htonl(jnum)), sizeof(x));
return (*jenv)->NewStringUTF(jenv, x);

}

***********************Jniprueba.h*************************

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Jniprueba */

#ifndef _Included_Jniprueba
#define _Included_Jniprueba
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Jniprueba
* Method: convert
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_Jniprueba_convert
(JNIEnv *, jobject, jint);

#ifdef __cplusplus
}
#endif
#endif

I don't know what must I do. Thanks

Topic: Hibernate - Criteria Previous Topic   Next Topic Topic: need help in integrating java w/ sql server 2000 reporting services

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use