Java - loading native libraries for 32 and 64 bit OS
Recently I had I problem with loading dll libraries for my java web start application. 32 bit library didn’t load on 64 bit OS and, of cause, vice verse.
Java has “arch” option for resources, and you can try to use it…
1 | <resources os="Windows" arch="x86"> |
But funny problem is that 64x Windows user sometimes installs 32 bit java machine. And it won’t load your 64 bit dll. Also, solution with
1 | System.getProperty("os.arch"); |
doesn’t help you for same reason - it shows OS version, not version of java machine.
You can try a bit cheating with
1 | is64bit = (System.getenv("ProgramFiles(x86)") != null); |
and
1 | try { |
One of the libraries loads anyway : )
Of cause, this solution is not cool and won’be acceptable if you have really large library files… But in most cases it’s fine.