You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu编译TinyB时CMake提示无法找到javah工具,求助解决方案

Fixing "Cannot locate javah executable" When Building TinyB with Java Support

Got it, this error pops up because javah was deprecated in JDK 9 and fully removed in later Java versions, but TinyB's Java CMake script still relies on this old tool. Let's fix this with one of two straightforward approaches:

Since you're building from source, modifying the Java CMake file is the cleanest long-term fix:

  • Open java/CMakeLists.txt in your TinyB source directory (the file referenced in your error).
  • Find the section where javah is being searched for and executed (around line 16).
  • Replace the javah references with javac using its -h flag—this flag does the same job javah used to do: generating JNI headers.

For example, if the original code looks like this:

find_program(JAVAH_EXECUTABLE javah REQUIRED)
add_custom_command(
    OUTPUT ${JNI_HEADERS}
    COMMAND ${JAVAH_EXECUTABLE} -jni -d ${CMAKE_CURRENT_BINARY_DIR} -classpath ${CLASSPATH} ${JAVA_CLASSES}
    DEPENDS ${JAVA_SOURCES}
)

Change it to:

find_program(JAVAC_EXECUTABLE javac REQUIRED)
add_custom_command(
    OUTPUT ${JNI_HEADERS}
    COMMAND ${JAVAC_EXECUTABLE} -h ${CMAKE_CURRENT_BINARY_DIR} -classpath ${CLASSPATH} ${JAVA_SOURCES}
    DEPENDS ${JAVA_SOURCES}
)

2. Fall Back to JDK 8 (No Source Modifications Needed)

If you'd rather not tweak the code, install JDK 8 (which still includes javah) and point CMake to it:

  • Install OpenJDK 8 on Ubuntu:
    sudo apt update && sudo apt install openjdk-8-jdk
    
  • Clear any existing CMake cache to avoid conflicts:
    rm -rf CMakeFiles CMakeCache.txt
    
  • Run CMake with the JDK 8 path (adjust the path if your JDK is installed in a different location):
    cmake -DBUILDJAVA=ON -DJAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
    

Wrap-Up

After applying either fix, re-run your CMake command and continue the build:

cmake -DBUILDJAVA=ON
make
sudo make install

内容的提问来源于stack exchange,提问作者Black Boy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 11:13:40