11

So I'm trying to run the 'javah' tool on a compiled .class file in Eclipse, but I have no idea how to do it. The examples I found simply said something along the lines of 'run javah on your class...' but I don't really know where I'd find such a command line in Eclipse.

If someone can give me a set of idiot proof instructions get this done in Eclipse, I'd be grateful.

Thanks :)

bobby
  • 2,629
  • 5
  • 30
  • 56
sparkFinder
  • 3,336
  • 10
  • 42
  • 57
  • Hi, See my answer here: http://stackoverflow.com/questions/11269511/how-to-configure-javah-tool-in-eclipse/14855418#14855418 Hope it'll help you. – marienke Feb 13 '13 at 14:14

2 Answers2

19

AFAIK Eclipse does not integrate javah by default. You have to set it up as external tool yourself.

  1. Create a new external tool
  2. Set the path to javah (on linux this was /user/bin/javah)
  3. Set the working dir to ${project_loc}/bin/ where bin is your Projects output directory
  4. Add ${java_type_name} to the arguments

With this setup you can call javah as external tool on any java file in the Package explorer. The generated header files currently land in the bin dir, this can be changed by adding the -d option.

josefx
  • 15,506
  • 6
  • 38
  • 63
  • 1
    Is ${java_type_name} a pre-existing variable? – sparkFinder Aug 10 '10 at 20:44
  • @sparkFinder I just checked the documentation, it is not listed with the default workspace variables - It could be limited to Java projects. – josefx Aug 11 '10 at 06:52
  • I get Error: Could not find class file for 'WinLockUnlock.Happy'. where happy is my class name. – Sathish Kumar k k Apr 21 '12 at 05:44
  • 1
    Found a post saying it should be -jni ${java_type_name} http://stackoverflow.com/questions/4168033/using-javah-jni-with-an-eclipse-project-structure?rq=1 – marienke Feb 13 '13 at 13:32
  • 1
    Also found a post stating that the "working directory" should be /bin/classes/ not just /bin/ - this worked for me. – marienke Feb 13 '13 at 13:54
5

Here is a sample command line:

javah -classpath /path/to/project/classes com.mycompany.MyClass

/path/to/project/classes - This is the 'Output folder' from the Source tab of Java Build Path properties page for you project.

It may be relative to the directory from where you are running javah.

You may use -verbose flag to see more details about what's going on.

Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121