How does the JVM find Native functions?

hwadechandler-openjdk at hwadechandler-openjdk at
Wed Jan 26 16:03:01 UTC 2011

Is a good simple start. But, if you used javah, then it should have defined the 
functions needed to be implemented. Are you sure it is loading your library? How 
do you know for sure? Do you have a static section using System.loadLibrary and 
there is no exception raised there? If it is throwing an exception there, then 
it most likely isn't finding the library, and definitely isn't loading it. It 
may be it is finding your library, but is failing to load some other dependency 
as well.

You can hook up a debugger in your C environment and set a break point in what 
ever entry point you have in the DLL/SO to know if it is loading that at least. 
If the actual file is being hooked into the JVM and loaded and the entry point 
called, then it may be a naming issue. Did you change your function names to 
something other than what javah output in your headers?

See the overall book from above:

Is a good way to go. Too, if your classes with the native methods are in 
packages, then notice the Java_my_package_myFunction naming scheme. That is all 
that is needed as long as you are outputting a C library. If you are using C++  
then you will have to use extern "C" to make sure name mangling doesn't occur. 
If you don't know about name mangling, then just google it, and you'll find what 
you need.

Hope something helps,


Wade Chandler
Software Engineer and Developer
NetBeans Dream Team Member and Contributor

----- Original Message ----
> From: John J. Boyer <john.boyer at>
> To: discuss at
> Sent: Tue, January 25, 2011 11:28:04 PM
> Subject: How does the JVM find Native functions?
> I have created bindings for a C library. The Java program seems to load 
> the  library, but when I try to use a method which is declared native I 
> always  get UnsatisfiedLinkError. I used javah to create the headings, 
> then derived  the program from the headings. It looks to me like the 
> methods have to be  registered in some way. How do I go about this? How 
> does the JVM find the  native function corresponding to a native  method?
> Thanks,
> John
> -- 
> John J. Boyer; President, Chief  Software Developer
> Abilitiessoft,  Inc.
> Madison, Wisconsin USA
> Developing  software for people with disabilities

More information about the discuss mailing list