在CentOS上进行Java编译时,遵循一些最佳实践可以帮助确保编译过程的高效性和代码的质量。以下是一些关键的最佳实践:
yum groupinstall "Development Tools"
yum install -y freetype-devel cups-devel libXtst-devel libXt-devel libXrender-devel libXrandr-devel libXi-devel libasound2-devel libffi-devel autoconf
wget https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
tar -xzvf openjdk-11.0.2_linux-x64_bin.tar.gz -C /opt/
echo "export JAVA_11_HOME=/opt/jdk-11.0.2" >> ~/.bashrc
echo "export PATH=$JAVA_11_HOME/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
yum install ccache -y
export PATH="/usr/lib64/ccache:$PATH"
cat /proc/cpuinfo
export CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer"
export CXXFLAGS="${CFLAGS}"
make -j$(nproc) # 利用所有CPU核心加速编译
StringBuilder代替+进行字符串拼接。list.size()等方法。-Xmx和-Xms)。vm.swappiness以优化内存管理。mvn clean package
gradle clean build
通过遵循这些最佳实践,可以在CentOS上高效且安全地进行Java代码的编译和部署。