2015-11-20

[JAVA] JNI용 C header file 생성 (javah)

오랜만에 JNI를 사용하여 라이브러리를 작성할 일이 생겼다.
JNI를 사용할 때 c 함수 형태를 java code에서 호출할 수 있게 생성해야한다.
이를 쉽게 해주는 tool이 javah인데, 너무 오랜만에 사용했더니 사용법잘생각이 안났다.
나중에 다시 찾을때를 위해 간단히 기록해둔다.

javah help 페이지는 아래와 같다.
> javah --help
Usage:
  javah [options] <classes>
where [options] include:
  -o <file>                Output file (only one of -d or -o may be used)
  -d <dir>                 Output directory
  -v  -verbose             Enable verbose output
  -h  --help  -?           Print this message
  -version                 Print version information
  -jni                     Generate JNI-style header file (default)
  -force                   Always write output files
  -classpath <path>        Path from which to load classes
  -cp <path>               Path from which to load classes
  -bootclasspath <path>    Path from which to load bootstrap classes
<classes> are specified with their fully qualified names
(for example, java.lang.Object).

example)
> javah -classpath E:\workspace\android\testpackage\src\main\java>javah -classpath C:\Android\sdk\platforms\android-23\andro
id.jar; testpackage.TestClass