Resolve Java dependency and native library compatibility issues when migrating from x86 to ARM-based YiTian ECS instances.
Background
Java applications may call native C libraries through dependencies or Java Native Interface (JNI). Direct migration can cause compatibility issues. Use the following methods to resolve them:
-
Upgrade the required dependencies if Java dependencies are incompatible with the ARM platform.
-
Rebuild Java projects to resolve native library issues.
Select a JDK
Arm is widely adopted in server environments. A suitable Java Development Kit (JDK) reduces compatibility issues and improves performance. The following OpenJDK distributions are recommended for YiTian ECS instances:
-
Alibaba Dragonwell: an open source OpenJDK distribution by Alibaba, optimized for stability and performance of large-scale Java applications in data centers. See Alibaba Dragonwell.
-
Eclipse Temurin: an open source Java SE build based on OpenJDK, compatible with multiple platforms and Java SE versions. See Eclipse Temurin.
Upgrade the required dependencies
Some Java dependencies include x86-only native libraries. If an error similar to the following is reported when you run an application, upgrade the dependencies to resolve the issue.
Exception in thread "main" java.lang.UnsatisfiedLinkError: xxx.so: xxx.so:
cannot open shared object file: No such file or directory (Possible cause: can't load AMD 64-bit .so on a AARCH64-bit platform)
-
Scanning for incompatible dependencies
Scan SO files to identify incompatible dependencies. If only x86 SO files are found, the dependency may not support ARM.
Save the following script to the compiled application directory and run it to scan SO files.
WarningDo not use this script in production environments.
#!/bin/bash rm -rf tmp mkdir tmp for jar in $(find . -name "*.jar") do if [ -f $jar ] then echo $jar cp -r $jar tmp/ fi done cd tmp for test in `ls` do name=`echo $test | sed "s/.jar//g"` echo $name mkdir $name cp -r $test $name cd $name unzip -o $test cd .. done echo "========= starting Analysis ==========" find . -name "*.so" -exec file {} \;The following sample output shows that lz4-1.3.0 contains three x86 SO files that do not support ARM. Upgrade lz4-1.3.0 to 1.4.0 to resolve this issue.
lz4 is renamed was renamed to lz4-java in version 1.4.0 and later.
========= starting Analysis ========== ./lz4-1.3.0/win32/amd64/liblz4-java.so: PE32+ executable (DLL) (console) x86-64, for MS Windows ./lz4-1.3.0/linux/amd64/liblz4-java.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=2eafd0d4e86904e188b47565639318325108fffa, not stripped ./lz4-1.3.0/linux/i386/liblz4-java.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=41041674439aea5d1fd6c62b6d88f63da7600c9f, not stripped -
Common dependencies that may have compatibility issues
The following table lists common dependencies with known compatibility issues. Upgrade them to the recommended versions.
Dependency name
Recommended version
lz4-java
1.4.0
jna
5.2.2
snappy-java
1.1.3
icu4j
68.1
sqlite-jdbc
3.20.0
forest-sqlite-jdbc
3.32.3.3
netty-tcnative
2.0.31
netty-transport-native-epoll
4.1.50
Rebuild a Java project
Common build tools such as Maven are architecture-independent and require no changes. Configure the JDK before rebuilding. See Select a JDK.