Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Need help generating header files via jni

Reply
Thread Tools

Need help generating header files via jni

 
 
catherineattriangle@gmail.com
Guest
Posts: n/a
 
      07-14-2005
Hi everyone,

I am having some problems generating header files via Java. The actual
case is more complicated, but this example explains my current
stumbling block:

This is the code I'm putting through javah:

public class Demonstration
{
public String publicName;
private String privateName;
public static String publicStaticName;
private static String privateStatucName;

public native void method1();
public native int method2(boolean b, byte by, char c, short s);
public native byte[] method3(byte data[], boolean b[]);
public native String[] method4(int num, long l, float f, double d);

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


This is the .h file that results:

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

#ifndef _Included_Demonstration
#define _Included_Demonstration
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: publicStaticName */
/* Inaccessible static: privateStatucName */
/*
* Class: Demonstration
* Method: method1
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_Demonstration_method1
(JNIEnv *, jobject);

/*
* Class: Demonstration
* Method: method2
* Signature: (ZBCS)I
*/
JNIEXPORT jint JNICALL Java_Demonstration_method2
(JNIEnv *, jobject, jboolean, jbyte, jchar, jshort);

/*
* Class: Demonstration
* Method: method3
* Signature: ([B[Z)[B
*/
JNIEXPORT jbyteArray JNICALL Java_Demonstration_method3
(JNIEnv *, jobject, jbyteArray, jbooleanArray);

/*
* Class: Demonstration
* Method: method4
* Signature: (IJFD)[Ljava/lang/String;
*/
JNIEXPORT jobjectArray JNICALL Java_Demonstration_method4
(JNIEnv *, jobject, jint, jlong, jfloat, jdouble);

#ifdef __cplusplus
}
#endif
#endif


Whatever happened to public String publicName and private String
privateName? I'm at my wits' end from trying to figure this out. If
this helps, I am using NetBeans IDE 4.1 and using the default Ant XML
file with this added:

<target name="-post-compile">
<javah destdir="headers" classpath="build\classes\"
verbose="yes">
<class name="Demonstration"/>
</javah>
</target>

If anyone could help, that would be great.

Catherine

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      07-14-2005
On 14 Jul 2005 12:50:34 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I am having some problems generating header files via Java. The
> actual case is more complicated, but this example explains my
> current stumbling block:
>
> Whatever happened to public String publicName and private String
> privateName?


There is nothing wrong with the file. The primary purpose of the
header is to provide you with the necessary signatures of your native
*methods*.

If your static fields had been final and given initial values, javah
could have defined "convenience" constants that you could use in your
native methods, something like this:

#define Java_Demonstration_foo 10

That way you could have used the value in your native code without
having to look up the static field itself. In the case of non-final
statics, it isn't meaningful to generate constants for use in the
native code, and javah has reported that as comments in the header.
Javah doesn't even consider the non-static member fields, since you
always need to get their values from the containing objects.

It's important to remember that your native methods are part of the
class itself, the same way that your java methods are, and as such
always have full access to *all* of the class' methods and fields.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
 
catherineattriangle@gmail.com
Guest
Posts: n/a
 
      07-14-2005
Gordon,

Thanks very much for your answer. That clears up a few things. However,
I have a follow up question.

I have another file (the one because of which I'm working on all this)
which looks something like this:



public final class TOMSClient implements javax.jms.MessageListener,

javax.jms.ExceptionListener{

private static final int SourceID = 1;
private static final int RegionID = 1;
private static final int TimeZoneOffset = 0;
private static SpeedForDatabase DatabaseSpeed = new
SpeedForDatabase();
private static EventForDatabase DatabaseEvent = new
EventForDatabase();
private static int ConnectionCount = 0;
private static final int Connectioncpy = 279;
private static java.sql.Connection connection = null;//Load the
library
static {
System.loadLibrary("TOMSClientHelper");
}

/** Types of the requests supported by the TOMSDI server. SHOULD
NOT BE CHANGED */
private static final int REQUEST_TYPE_INCIDENTS = 3; //
active events
private static final int REQUEST_TYPE_EVENTS = 4; //
scheduled events
private static final int REQUEST_TYPE_ROADS = 5; // links
definitions

/** Names of the root elements for published messages. SHOULD NOT
BE CHANGED */
private static final String
PUBLISH_TYPE_TRAVELER_INFO_RESPONSE_ROOT =
"TravelerInformationResponse";
private static final String
PUBLISH_TYPE_EVENT_REPORT_MESSAGE_ROOT = "EventReportMessages";

/**
* A message property that will allow the server application to
log in a
* requestor IP address (for troubleshooting). SHOULD NOT BE
CHANGED.
*/
private static final String MSG_PROP_REQUESTOR_IPADDRESS =
"RequestorIPAddress";

/* END of restricted section */

/** Types of TravelerInformationResponse data */
private static final int TRAVELER_INFO_RESPONSE_TYPE_UNDEFINED
= 0;
private static final int TRAVELER_INFO_RESPONSE_TYPE_LINK_STATUS
= 1;
private static final int
TRAVELER_INFO_RESPONSE_TYPE_SCHEDULED_EVENT = 2;

/**
* The singleton TOMSClient object.
*/
private static TOMSClient m_tomsClient =
null;

...............MORE MEMBERS................
...............SOME METHODS................
public static native int GetIncidentDirection(String Highway, double
lon1, double lat1,int RegionID, String direction, int nodeID1, int
nodeID2, double lon2, double lat2);

public static native boolean isSeriousIncident(int segmentID, int
direction, int regionID);

...............A COUPLE OF PRIVATE CLASSES.........
}


The above code generates the following .h file:

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

#ifndef _Included_client_TOMSClient
#define _Included_client_TOMSClient
#ifdef __cplusplus
extern "C" {
#endif
#undef client_TOMSClient_REQUEST_TYPE_INCIDENTS
#define client_TOMSClient_REQUEST_TYPE_INCIDENTS 3L
#undef client_TOMSClient_REQUEST_TYPE_EVENTS
#define client_TOMSClient_REQUEST_TYPE_EVENTS 4L
#undef client_TOMSClient_REQUEST_TYPE_ROADS
#define client_TOMSClient_REQUEST_TYPE_ROADS 5L
#undef client_TOMSClient_TRAVELER_INFO_RESPONSE_TYPE_UNDE FINED
#define client_TOMSClient_TRAVELER_INFO_RESPONSE_TYPE_UNDE FINED 0L
#undef client_TOMSClient_TRAVELER_INFO_RESPONSE_TYPE_LINK _STATUS
#define client_TOMSClient_TRAVELER_INFO_RESPONSE_TYPE_LINK _STATUS 1L
#undef client_TOMSClient_TRAVELER_INFO_RESPONSE_TYPE_SCHE DULED_EVENT
#define client_TOMSClient_TRAVELER_INFO_RESPONSE_TYPE_SCHE DULED_EVENT
2L
/* Inaccessible static: m_tomsClient */
#ifdef __cplusplus
}
#endif
#endif

So there are two problems with this: first and foremost, where are my
native classes? Second, why are only some of the private static final
members included in the .h file? (Connectioncpy isn't, for example.)
This is less important, but maybe the two are connected?

If you could shed some light on this, it'd be extremely helpful.

Thanks,

Catherine

Gordon Beaton wrote:
> On 14 Jul 2005 12:50:34 -0700, (E-Mail Removed) wrote:
> > I am having some problems generating header files via Java. The
> > actual case is more complicated, but this example explains my
> > current stumbling block:
> >
> > Whatever happened to public String publicName and private String
> > privateName?

>
> There is nothing wrong with the file. The primary purpose of the
> header is to provide you with the necessary signatures of your native
> *methods*.
>
> If your static fields had been final and given initial values, javah
> could have defined "convenience" constants that you could use in your
> native methods, something like this:
>
> #define Java_Demonstration_foo 10
>
> That way you could have used the value in your native code without
> having to look up the static field itself. In the case of non-final
> statics, it isn't meaningful to generate constants for use in the
> native code, and javah has reported that as comments in the header.
> Javah doesn't even consider the non-static member fields, since you
> always need to get their values from the containing objects.
>
> It's important to remember that your native methods are part of the
> class itself, the same way that your java methods are, and as such
> always have full access to *all* of the class' methods and fields.
>
> /gordon
>
> --
> [ do not email me copies of your followups ]
> g o r d o n + n e w s @ b a l d e r 1 3 . s e


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-15-2005
On 14 Jul 2005 12:50:34 -0700, "(E-Mail Removed)"
<(E-Mail Removed)> wrote or quoted :

>Whatever happened to public String publicName and private String
>privateName? I'm at my wits' end from trying to figure this out. If
>this helps, I am using NetBeans IDE 4.1 and using the default Ant XML
>file with this added:


they are not native so they are not part of the JNI interface.

You can get at them by a sort of reflection process, but it would be
easier to just pass them as parameters to one of your native methods.


--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      07-15-2005
On 14 Jul 2005 15:44:18 -0700, (E-Mail Removed) wrote:
> So there are two problems with this: first and foremost, where are my
> native classes?


Methods, I think you mean here.

> Second, why are only some of the private static final members
> included in the .h file? (Connectioncpy isn't, for example.) This is
> less important, but maybe the two are connected?


Based on what you've posted, I can't really see why javah is being
selective about this.

I suspect one of the following:

- after adding the missing members and method declarations to your
code, you ran javah without recompiling the class first.

- javah sees a different version of the classfile than you think it
does. Do you have stray copies of TOMSClient.class that should be
removed?

My suggestion is to run "javap -p TOMSClient" to see what it says
about your class. Do you see the missing items?

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
UNIX header files to Windows header files anand.ba@gmail.com C Programming 3 05-01-2006 03:57 PM
Auto-generating C header file from C++ header? Bit byte C++ 1 04-19-2006 01:40 AM
Location of JDK header files (for JNI code) Torsten Landschoff Java 13 09-14-2005 12:42 PM
Header files included in header files John Smith C Programming 18 07-24-2004 04:55 AM



Advertisments