Running 32bit java program in 64bit Linux (jMRUI)
First, why? It is well known that 64 bit java platform can run java code compiled in 32 bit development environment. However, some java codes call C++ libraries.
For example, if for some reason you will have to run a very old – stopped developing program, like jMRUI, which was programmed in the 32 bit era, with all 32 bit libs. If you load it with 64 bit java, the java part will run properly. However, the other old 32 bit c++ libs, like libfftw.so, will get wrong ELF class error, like
libfftw.so: wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)
In this case, you must have 32 bit java platform to run it properly.
In 64 bit linux (CentOs for example), if you already have 64bit linux installed, like
java-1.7.0-openjdk-1.7.0.55-2.4.7.1.el6_5.x86_64
java-1.6.0-openjdk-1.6.0.0-5.1.13.3.el6_5.x86_64
and you try to download and install a 32bit version:
yum install java-1.6.0-openjdk-1.6.0.0-6.1.13.4.el6_5.i686.rpm
you will get
Examining java-1.6.0-openjdk-1.6.0.0-6.1.13.4.el6_5.i686.rpm: 1:java-1.6.0-openjdk-1.6.0.0-6.1.13.4.el6_5.i686
Marking java-1.6.0-openjdk-1.6.0.0-6.1.13.4.el6_5.i686.rpm as an update to 1:java-1.6.0-openjdk-1.6.0.0-5.1.13.3.el6_5.x86_64
Error: Nothing to do
which means that the yum wants to update the 64 bit version by the 32 bitc version. For sure this won’t work out.
However, java 32 bit version is surely possible to work in 64 bit OS.
You may look into /usr/lib/jvm and see the parallelly installed javas:
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64
/usr/lib/java-1.7.0-openjdk-1.7.0.55.x86_64
Then how to do it?
It is too much a work to self-compile java.
Here is a short cut:
1. You install a 32 bit linux virtual machine, or if you still have a 32bit linux computer, it will be easier. (Do not worry, I am not suggesting you to do your work in a slow 32 bit virtual machine.)
2. Install Java inside the 32 bit box, either virtual or real, does not matter.
3. Copy all content in the /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.?? to your jump drive using
rsync -av java-1.7.0-openjdk-1.7.0.?? /your_jump_drive/
4. Plug your jump drive into your 64bit computer, copy the java to its proper place:
rsync -av /your_jump_drive/java-1.7.0-openjdk-1.7.0.?? /usr/lib/jvm/
5. Now you have your 32bit java in your lib location. You may leave it as is, or cover it by running
yum install java-1.6.0-openjdk-1.6.0.0-6.1.13.4.el6_5.i686.rpm
This time it will work.
6. Modify your script of starting your java program. As for jMRUI, revise the file
jmrui.sh
replace the work java with
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.??/bin/java -d32
where the ?? is the subversion of java you installed. For my current case, 55.
To make the file from
java -Xss2m -mx1200m -Djava.library.path=lib -jar lib/mrui.jar
to
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.55/bin/java -d32 -Xss2m -mx1200m -Djava.library.path=lib -jar lib/mrui.jar
Now, your old 32bit java based software will work properly.
Have fun!