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:
1. Update TinyB's CMake Script to Use Modern javac (Recommended)
Since you're building from source, modifying the Java CMake file is the cleanest long-term fix:
- Open
java/CMakeLists.txtin your TinyB source directory (the file referenced in your error). - Find the section where
javahis being searched for and executed (around line 16). - Replace the
javahreferences withjavacusing its-hflag—this flag does the same jobjavahused 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
相关产品推荐
相关产品推荐

