Skip to content

Instantly share code, notes, and snippets.

@nilput
Created May 11, 2020 05:48
Show Gist options
  • Select an option

  • Save nilput/c0ff83fed6a07fd6e9c3a76ac942c93c to your computer and use it in GitHub Desktop.

Select an option

Save nilput/c0ff83fed6a07fd6e9c3a76ac942c93c to your computer and use it in GitHub Desktop.
Javaheader - a script to generate a JNI header from a java source file
#!/bin/bash
function die() {
rm -r "$tmp_dir"
exit 1;
}
if [ "$#" -lt 1 ]; then
echo "Usage: $0 [java source file]"
exit 1;
fi
tmp_dir="$(mktemp -d -t javah-XXXXXXXXXX)"
[ -d "$tmp_dir" ] || exit 1;
javac -d "$tmp_dir" "$1" || die;
cd "$tmp_dir" || die;
classqual="$(find . -type f | sed 's/.class//' | sed 's#./##' | sed 's#/#.#g')"
javah -cp . "$classqual" || die;
cat "$(find . -name '*.h')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment