1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
<title>Javah Task</title>
</head>
<body>
<h2 id="javah">Javah</h2>
<h3>Description</h3>
<p>Generates JNI headers from a Java class.</p>
<p>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 <a href="https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javah.html"
target="_top">JDK 1.2+</a>
or <a href="https://web.archive.org/web/20021018232717/http://java.sun.com/products/jdk/1.1/docs/tooldocs/win32/javah.html"
target="_top">pre-1.2 JDK</a> systems are used.</p>
<p>If you are building with Java 8 or above consider
using <a href="javac.html"><code>javac</code></a>'s <var>nativeheaderdir</var> attribute instead
which allows you to compile the classes and generate the native header files in a single step.</p>
<p><strong>Note</strong>: <code>javah</code> has been deprecated in Java 9 and removed in Java
10. Attempts to use it with Java 10 will fail.</p>
<p id="implementationvalues">It is possible to use different compilers. This can be selected with
the <var>implementation</var> attribute or a nested element. Here are the choices of the
attribute:</p>
<ul>
<li><q>default</q>—the default compiler for the platform.</li>
<li><q>sun</q>—the standard compiler of the JDK.</li>
<li><q>kaffeh</q>—the native standard compiler of <a href="http://www.kaffe.org"
target="_top">Kaffe</a>.</li>
<li><q>gcjh</q>—the native standard compiler
of <a href="https://gcc.gnu.org/gcc-7/changes.html#java" target="_top">gcj and
gij</a>. <em>Since Apache Ant 1.8.2</em></li>
<li><q>forking</q>—runs the <code>javah</code> executable via its command line interface in
a separate process. Default when not running on Kaffe or gcj/gij <em>since Ant 1.9.8</em></li>
</ul>
<p><strong>Note</strong>: if you are using this task to work on multiple files the command line may
become too long on some operating systems. Unfortunately the <code>javah</code> command doesn't
support command argument files the way <code>javac</code> (for example) does, so all that can be
done is breaking the amount of classes to compile into smaller chunks.</p>
<h3>Parameters</h3>
<table class="attr">
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Required</th>
</tr>
<tr>
<td>class</td>
<td>the fully-qualified name of the class (or classes, separated by commas)</td>
<td>Yes</td>
</tr>
<tr>
<td>outputFile</td>
<td>concatenates the resulting header or source files for all the classes listed into this
file</td>
<td rowspan="2">Exactly one of the two</td>
</tr>
<tr>
<td>destdir</td>
<td class="left">sets the directory where <code>javah</code> saves the header files or the stub
files.</td>
</tr>
<tr>
<td>force</td>
<td>specifies that output files should always be written (JDK 1.2 only)</td>
<td>No</td>
</tr>
<tr>
<td>old</td>
<td>specifies that old JDK 1.0-style header files should be generated (otherwise output file
contain JNI-style native method function prototypes) (JDK 1.2 only)</td>
<td>No</td>
</tr>
<tr>
<td>stubs</td>
<td>generate C declarations from the Java object file (used with <var>old</var>)</td>
<td>No</td>
</tr>
<tr>
<td>verbose</td>
<td>causes <code>Javah</code> to print a message concerning the status of the generated
files</td>
<td>No</td>
</tr>
<tr>
<td>classpath</td>
<td>the classpath to use</td>
<td>No</td>
</tr>
<tr>
<td>bootclasspath</td>
<td>location of bootstrap class files</td>
<td>No</td>
</tr>
<tr>
<td>extdirs</td>
<td>location of installed extensions</td>
<td>No</td>
</tr>
<tr>
<td>implementation</td>
<td>The compiler implementation to use. (See the above <a href="#implementationvalues">list</a>
of valid compilers.)</td>
<td>No; defaults to default compiler for the current JDK</td>
</tr>
</table>
<h3>Parameters specified as nested elements</h3>
<h4>arg</h4>
<p>You can specify additional command line arguments for the compiler with
nested <code><arg></code> elements. These elements are specified
like <a href="../using.html#arg">Command-line Arguments</a> but have an additional attribute that
can be used to enable arguments only if a given compiler implementation will be used.</p>
<table class="attr">
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Required</th>
</tr>
<tr>
<td>value</td>
<td rowspan="4">See <a href="../using.html#arg">Command-line Arguments</a>.</td>
<td rowspan="4">Exactly one of these</td>
</tr>
<tr>
<td class="var">line</td>
</tr>
<tr>
<td class="var">file</td>
</tr>
<tr>
<td class="var">path</td>
</tr>
<tr>
<td>prefix</td>
<td rowspan="2">See <a href="../using.html#arg">Command-line Arguments</a>. <em>Since Ant
1.8</em>.</td>
<td>No</td>
</tr>
<tr>
<td>suffix</td>
<td>No</td>
</tr>
<tr>
<td>implementation</td>
<td>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 <a href="#implementationvalues">list</a> of valid compilers.)</td>
<td>No</td>
</tr>
</table>
<h4>implementationclasspath</h4>
<p><em>Since Ant 1.8.0</em></p>
<p>A <a href="../using.html#path">path-like structure</a> holding the classpath to use when loading
the compiler implementation if a custom class has been specified. Doesn't have any effect when
using one of the built-in compilers.</p>
<h4>Any nested element of a type that implements JavahAdapter</h4>
<p><em>Since Ant 1.8.0</em></p>
<p>If a defined type implements the <code>JavahAdapter</code> interface a nested element of that
type can be used as an alternative to the <var>implementation</var> attribute.</p>
<h3>Examples</h3>
<pre><javah destdir="c" class="org.foo.bar.Wibble"/></pre>
<p>makes a JNI header of the named class, using the JDK 1.2 JNI model. Assuming the
directory <samp>c</samp> already exists, the file <samp>org_foo_bar_Wibble.h</samp> is created
there. If this file already exists, it is left unchanged.</p>
<pre>
<javah outputFile="wibble.h">
<class name="org.foo.bar.Wibble,org.foo.bar.Bobble"/>
</javah></pre>
<p>is similar to the previous example, except the output is written to a file
called <samp>wibble.h</samp> in the current directory.</p>
<pre>
<javah destdir="c" force="yes">
<class name="org.foo.bar.Wibble"/>
<class name="org.foo.bar.Bobble"/>
<class name="org.foo.bar.Tribble"/>
</javah></pre>
<p>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 <code>Javah</code> task is invoked, even if they
already exist.</p>
<pre>
<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></pre>
<p>writes the headers for the three classes using the 'old' JNI format, then writes the
corresponding <samp>.c</samp> stubs. The verbose option will cause <code>Javah</code> to describe
its progress.</p>
<p>If you want to use a custom JavahAdapter <code>org.example.MyAdapter</code> you can either use
the implementation attribute:</p>
<pre>
<javah destdir="c" class="org.foo.bar.Wibble"
implementation="org.example.MyAdapter"/></pre>
<p>or a define a type and nest this into the task like in:</p>
<pre>
<componentdef classname="org.example.MyAdapter"
name="myadapter"/>
<javah destdir="c" class="org.foo.bar.Wibble">
<myadapter/>
</javah></pre>
<p>in which case your <code>javah</code> adapter can support attributes and nested elements of its
own.</p>
</body>
</html>
|