Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Mar 21, 2003

Generate a Native Header File and Copy It to the Desired Directory


If you have used a native method through a Java interface, then you might already know that a header file is generated from the Java class that contains the native method declaration. This header file is then included in the C or C++ file, where you implement the native method, declared in the Java file. The header file is generated using the "javah" utility, which comes with the Java Standard Edition. Mostly, the Java source file is a part of the package. To make the native call work properly, the header file name must be derived from the package name and class name. The following command does it in one step:
 
javah -d [directory where you want the header file] classname

For example, if you declare a native method in the Java file "SharedMemory.java" as shown below, and you want the header file to be in the same directory where the Java source files are.
 
	package com.mycompany.sysutil;

	public class SharedMemory
	{
		//create the shared and intialize with the value
		public native int createShm(int shm_key, String value);
	}

Then the command to generate a header file will be:
 
javah -d com/mycompany/sysutil/. com.mycompany.sysutil.SharedMemory
Rajiv Sharma
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date