Reputation: 191
My application consists of three components:
Please note that JNI library is built for 32 bit. On 32 bit OS, applet uses java.home
property to get the JRE path. Once applet gets JRE path, it launches JAR like this
JRE-path myapp.jar
Now I need to run this application on 64 bit Linux. Here I have two options:
java.home
property gives the 64 bit JRE path. ( Because browser and plugins are 64 bit). One option is to use update-alternatives –list java
command to get all JRE installations path. Then for each installation path, run JRE-path -d32 –version
command to see whether it supports 32 bit JVMQuestion:
Upvotes: 2
Views: 1930
Reputation: 94654
Use option 1. Build both a 32bit and 64bit JNI library and load the relevant .so based on being on a 32-bit or 64-bit VM.
You can use the sun.arch.data.model
system property for the Sun JDK
You can use the com.ibm.vm.bitmode
for the IBM websphere VM
Or look for the substring 64
in the os.arch
system property (it's x86_64/amd64 on 64bit intel based VMs)
As you cannot build a 64bit variant of the .so
and all it's dependent .a
and .so
files (this is actually good software configuration management practice), then the following shell script should be a good effort. If at the end of calling it the script exits with 66
, then there is no valid 32bit java
#!/bin/bash -p
# attempt to find a 32bit VM
# uses a dummy class file (it's just an empty file)
trap 'rm -f /tmp/testclass$$.class /tmp/jlocations.$$' EXIT HUP
touch /tmp/testclass$$.class
tryj() {
while read java; do
errout=$($java -cp /tmp -d32 testclass$$ 2>&1)
if grep -q 'java.lang.ClassFormatError' <<<$errout; then
# good VM - run with this
rm -f /tmp/testclass$$.class /tmp/jlocations.$$
# echo $java "$@"
exec $java "$@"
fi
done </tmp/jlocations.$$
return 1
}
# try update-alternatives - debian/ubuntu
update-alternatives --list java > /tmp/jlocations.$$ 2>/dev/null
tryj "$@"
# Try alternatives - redhat
alternatives --list java > /tmp/jlocations.$$ 2>/dev/null
tryj "$@"
# then try locate - generic linux/unix
locate java | grep 'bin/java$' > /tmp/jlocations.$$
tryj "$@"
# if we had no luck, then use find - this will be sloooooooooow
find / -wholename '*/bin/java' >/tmp/jlocations.$$ 2>/dev/null
tryj "$@"
exit 66
Upvotes: 1