Skip to content

fix: create the CDS archive folder before running a jar with --cds - #2818

Open
arsalankhan786777 wants to merge 1 commit into
jbangdev:mainfrom
arsalankhan786777:fix-2816-cds-archive-dir
Open

arsalankhan786777 wants to merge 1 commit into
jbangdev:mainfrom
arsalankhan786777:fix-2816-cds-archive-dir

Conversation

@arsalankhan786777

Copy link
Copy Markdown

With --cds on a jar file or a Maven coordinate, every run printed the program's output, then [error][cds] Unable to create shared archive file and ended with exit code 1. Nothing is built for these inputs, so the cache folder that -XX:ArchiveClassesAtExit points into was never created.

Fix. JarCmdGenerator now creates the archive's parent folder before adding -XX:ArchiveClassesAtExit.

Tests. I added TestRun.testCDSCreatesArchiveFolderForJar, which generates the command for hellojar.jar with --cds and checks that the archive folder exists. It is skipped on Java versions before 13.

Written with Claude Code (AI); tested locally with the following on Windows 11, with JDK 21 as the test JDK:

  • ./gradlew test --tests dev.jbang.cli.TestRun.testCDSCreatesArchiveFolderForJar -PtestJavaVersion=21: fails without the fix, passes with it.
  • ./gradlew formatCheck: passes.
  • ./gradlew test -PtestJavaVersion=21: 1122 tests, 25 failed, 52 skipped. Running the classes with failures (TestApp, TestEdit, TestEditLocate, TestEditWithPom, TestEditWithPackage, TestRun, TestSkill, TestSourcesMultipleSomeMissingFiles) without this change gives the same 25 failing test names.
  • Built launcher (./gradlew installDist), jbang --verbose --cds hello.jar run twice: before, both runs exit 1 with the error above; after, both exit 0, the first writes the archive and the second uses it.
  • The same two runs with the fix for com.github.lalyos:jfiglet:0.0.9: both exit 0, the second uses the archive.

Not run: integration tests, and the unit tests on the default Java 11 test JDK.

Fixes #2816

🤖 Generated with Claude Code

A jar file or Maven coordinate is not built, so nothing created the cache
folder that -XX:ArchiveClassesAtExit points into. The JVM could not write
the archive and every run ended with exit code 1.

Fixes jbangdev#2816

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

When Java 13 or later is used and the CDS archive does not exist, command generation now creates its parent directory before adding the archive-at-exit option. A test checks that the directory exists and the generated command includes that option.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 4e873

This change creates the missing CDS archive folder so that running --cds on a jar or Maven coordinate succeeds on the first run. It is a small, localized fix with a regression test, and no merge-blocking risk is evident.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--cds with a jar fails with exit code 1: the archive folder is never created

2 participants