I have a class file with a native method on a path while its dependencies live on a separate path in a different package. My tree looks something like:
[build/classes]$ tree -L 3
.
├── main
│ └── com
│ └── foo
└── test
└── com
└── foo
My dependencies live on the main path while the class file I'm trying to build the header for is on the test path. The files look something like:
// FooTest.java: class file will go to build/classes/test/com/foo/
package com.foo;
import com.foo.bar.Depend;
public class FooTest {
private native void baz(int i);
public FooTest() {
Depend depend = new Depend();
baz(depend.get());
}
}
// Depend.java: class file will go to build/classes/main/com/foo/bar
package com.foo.bar;
public class Depend {
public int get() { return 3; }
}
Now back to the build/classes
dir. Let's invoke our javah command:
[build/classes]$ javah -classpath "test/" com.foo.FooTest
Error: Class com.foo.bar.Depend could not be found.
Darn. It couldn't find the dependency. Shouldn't be surprised: it's not on the path! We'll use classpath separator ;
to send multiple searchpaths.
[build/classes]$ javah -classpath "test/;main/" com.foo.FooTest
Error: Could not find class file for 'com.foo.FooTest'.
What? It can't find the class file in the test
dir now. Flip the order of the paths? Turn on verbose? Write the full path?
[build/classes]$ javah -verbose -classpath "main/;test/" com.foo.FooTest
Error: Could not find class file for 'com.foo.FooTest'.
[build/classes]$ javah -verbose -classpath "/the_full_path/main/;/the_full_path/test/" com.foo.FooTest
Error: Could not find class file for 'com.foo.FooTest'.
Blast! I tried all the combinations! Verbose gives me nothing and I'm getting the same error. I've read quite a few of the similar questions including this highly voted answer but have not found a solution that works for me.