2

This is a question which puzzles me. javah needs a classpath, of bytecode-compiled classes, in order to generate its headers.

But there is javac which, presumably, builds an AST out of the source code, which could possibly be used by javah as well. Especially since native methods are easily spotted.

So, why does javah need the bytecode at all?

fge
  • 119,121
  • 33
  • 254
  • 329

1 Answers1

5

Just because that's how they wrote it. I agree, it absolutely could have been written to operate on source, but that's not what they did.

The somewhat interesting thing about the way it is written is that you can use it if you have source (by compiling it first) or if you don't have source; that means the way it's done is actually more flexible, not less.

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
  • That's true, but on the other hand it makes the JNI build process more complicated than it could be :/ – fge Dec 17 '11 at 19:32
  • @fge No it doesn't. You have one compiler, that compiles .java to .class; you have one javah, that processes .class to .c and .h. Making javah a compiler would introduce a risk of divergence between it and javac. – user207421 Dec 17 '11 at 23:45
  • @EJP not if they share their code! But anyway... I know I have to deal with it :/ – fge Dec 17 '11 at 23:53