You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Framework打包RPM后Jar无法执行:嵌套归档压缩异常

Fixing Spring Boot Executable Jar Failure After RPM Installation

Looks like you've hit a common pitfall with packaging Spring Boot executables as RPMs—rpmbuild's default behavior of repacking Jars breaks the nested archive structure that Spring Boot relies on. Let's break down the problem and fix it step by step.

The Root Cause

Your error message spells out the issue clearly:

Unable to open nested entry 'BOOT-INF/lib/commons-io-2.4.jar'. It has been compressed and nested jar files must be stored without compression.

Spring Boot's executable Jar requires all nested Jars under BOOT-INF/lib to be stored without compression (using the STORED entry type in the Jar archive). By default, rpmbuild automatically repacks Jar files to compress their contents, which re-compresses those nested Jars and makes them unreadable to the Spring Boot loader.


Step 1: Disable Jar Repacking in Your Spec File

Add this line at the top of your .spec file (right after the Name/Version definitions) to tell rpmbuild not to modify your Spring Boot Jar:

%global __jar_repack %{nil}

This disables the default macro that triggers Jar repacking, preserving the original structure of your executable Jar.

Step 2: Clean Up Your Spec File for Reliability

Your current .spec has some redundant and potentially problematic steps—let's fix those to avoid other issues:

  1. Simplify the %prep section:
    The %setup -q command already extracts your source tarball to the correct build directory. Remove the manual copy command, since it's redundant and could cause directory conflicts:

    %prep
    %setup -q
    
  2. Fix the %install pathing:
    Use RPM's built-in macros (like %{_builddir}) instead of hardcoded paths to make your spec file more portable. Update the %install section to:

    %install
    rm -rf $RPM_BUILD_ROOT
    # Create the target directory structure
    mkdir -p $RPM_BUILD_ROOT/opt/sample/sample-tool-1.0/
    # Copy the Jar from the extracted source directory
    cp %{_builddir}/%{name}-%{version}/%{name}-sample-0.0.10.BUILD-SNAPSHOT.jar $RPM_BUILD_ROOT/opt/sample/sample-tool-1.0/sample-tool.jar
    # Ensure executable permissions (optional but good practice)
    chmod 0755 $RPM_BUILD_ROOT/opt/sample/sample-tool-1.0/sample-tool.jar
    
  3. Clean up the %files section:
    Ensure %defattr is the first entry under %files (standard practice) and keep your directory structure intact:

    %files
    %defattr(-,root,root,-)
    /opt/sample/
    %doc
    

Step 3: Verify the Fix

After updating your spec file:

  • Rebuild the RPM with rpmbuild -ba your.spec
  • Install the RPM locally
  • Run your Jar again—this time it should load the nested Jars correctly without the compression error.

This works because disabling __jar_repack tells rpmbuild to treat your Spring Boot Jar as a binary file instead of modifying its internal structure. This preserves the STORED entry type for all nested Jars under BOOT-INF/lib, which the Spring Boot loader expects.

内容的提问来源于stack exchange,提问作者JeanP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:56:37