> For the complete documentation index, see [llms.txt](https://blog.cweihang.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blog.cweihang.io/java/note.md).

# JNI

## **javah**(2016-1-15)

使用javah可以自动从java文件生成jni头文件，

> 用法：javah \[选项] <类>
>
> 其中 \[选项] 包括：
>
> -help 输出此帮助消息并退出
>
> -classpath <路径> 用于装入类的路径
>
> -bootclasspath <路径> 用于装入引导类的路径
>
> -d <目录> 输出目录
>
> -o <文件> 输出文件（只能使用 -d 或 -o 中的一个）
>
> -jni 生成 JNI样式的头文件（默认）
>
> -version 输出版本信息
>
> -verbose 启用详细输出
>
> -force 始终写入输出文件

## Example：

工程结构如下： ![](/files/-L_G1DpACUD3XOUXC4bW)

执行：

```
javah -d lib -classpath out/production/VideoSvr -jni cwh.NVR.NVRNative
```

关键在于找到正确的classpath，注意-jni 类名要放在最后面写，否则会把-jni后面的东西都当做类名解析的。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://blog.cweihang.io/java/note.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
