## Javah

### Description

Generates JNI headers from a Java class.

When this task executes, it will generate the C header and source files that are needed to implement native methods. JNI operates differently depending on whether JDK1.2 (or later) or pre-JDK1.2 systems are used.

It is possible to use different compilers. This can be selected with the `implementation` attribute. Here are the choices:

- default - the default compiler (kaffeh or sun) for the platform.
- sun (the standard compiler of the JDK)
- kaffeh (the native standard compiler of Kaffe)

### Parameters

Attribute | Description | Required
class | the fully-qualified name of the class (or classes, separated by commas) | Yes
outputFile | concatenates the resulting header or source files for all the classes listed into this file | Yes
destdir | sets the directory where javah saves the header files or the stub files.
force | specifies that output files should always be written (JDK1.2 only) | No
old | specifies that old JDK1.0-style header files should be generated (otherwise output file contain JNI-style native method function prototypes) (JDK1.2 only) | No
stubs | generate C declarations from the Java object file (used with old) | No
verbose | causes Javah to print a message concerning the status of the generated files | No
classpath | the classpath to use. | No
bootclasspath | location of bootstrap class files. | No
extdirs | location of installed extensions. | No
implementation | The compiler implementation to use. If this attribute is not set, the default compiler for the current VM will be used. (See the above list of valid compilers.) | No

Either outputFile or destdir must be supplied, but not both.

### Parameters specified as nested elements

#### arg

You can specify additional command line arguments for the compiler with nested `<arg>` elements. These elements are specified like Command-line Arguments but have an additional attribute that can be used to enable arguments only if a given compiler implementation will be used.

Attribute | Description | Required
value | See Command-line Arguments. | Exactly one of these.
line
file
path
implementation | Only pass the specified argument if the chosen compiler implementation matches the value of this attribute. Legal values are the same as those in the above list of valid compilers.) | No

### Examples

      <javah destdir="c" class="org.foo.bar.Wibble"/>

makes a JNI header of the named class, using the JDK1.2 JNI model. Assuming the directory 'c' already exists, the file `org_foo_bar_Wibble.h` is created there. If this file already exists, it is left unchanged.

      <javah outputFile="wibble.h">
        <class name="org.foo.bar.Wibble,org.foo.bar.Bobble"/>
      </javah>

is similar to the previous example, except the output is written to a file called `wibble.h` in the current directory.

      <javah destdir="c" force="yes">
        <class name="org.foo.bar.Wibble"/>
        <class name="org.foo.bar.Bobble"/>
        <class name="org.foo.bar.Tribble"/>
      </javah>

writes three header files, one for each of the classes named. Because the force option is set, these header files are always written when the Javah task is invoked, even if they already exist.

      <javah destdir="c" verbose="yes" old="yes" force="yes">
        <class name="org.foo.bar.Wibble"/>
        <class name="org.foo.bar.Bobble"/>
        <class name="org.foo.bar.Tribble"/>
      </javah>
      <javah destdir="c" verbose="yes" stubs="yes" old="yes" force="yes">
        <class name="org.foo.bar.Wibble"/>
        <class name="org.foo.bar.Bobble"/>
        <class name="org.foo.bar.Tribble"/>
      </javah>

writes the headers for the three classes using the 'old' JNI format, then writes the corresponding .c stubs. The verbose option will cause Javah to describe its progress.