davsclaus opened a new pull request, #27266: URL: https://github.com/apache/camel/pull/27266
[CAMEL-25236](https://issues.apache.org/jira/browse/CAMEL-25236) ## Problem `camel run --example=route/content-based-router`, and other examples that read or write files, only worked when started from the example's own folder. The example is extracted to a temp folder, but the JVM keeps the working directory it was started in. So `file:orders` read an auto-created, empty `./orders` in the current folder, and the example did nothing. A JVM cannot change its own working directory. ## Change As decided on the ticket, there is no virtual file system. `camel run --example` now runs every example in a child JVM, started in the example's folder, in the same way the TUI already starts examples. - One code path for all examples, bundled or downloaded from GitHub. Relative paths (`file:orders`, `out/`, `parked/`) resolve to the example's files. - `ExampleHelper.runArgs` replaces `--example=name` (and `--example name`) with the example's files, plus `--name=<short name>` unless a name is given. The TUI's `LaunchManager.exampleArgs` now delegates to it, so the CLI and the TUI build the same command. - The child inherits the IO, so it runs in the foreground with its log visible. A shutdown hook stops the child when the launcher stops. - Startup prints `Example folder: ...`, so the files an example writes can be found. - `camel dev --example` and `camel debug --example` behave the same way, because the child keeps the subcommand. - Exporting and transforming don't run the routes, so they stay in the current JVM as before. - The run name is now the short name (`content-based-router`), as in the TUI, instead of `route/content-based-router`. ## Verified I used the launcher jar built from this branch, started from an empty folder: - `--example=route/content-based-router` (from GitHub) processes all three orders (ORD-1001 DK, ORD-1002 DE, ORD-1003 US) and exits 0. No `orders` folder is created in the current folder. - `--example=timer-log` (bundled) loads its own `application.properties` (`Hello Camel!`). - Killing only the launcher (SIGTERM) also stops the example's JVM, so no orphan is left behind. `ExampleHelperTest` (new `runArgsOfAnExample`), `ExampleRoutesLoadTest` and the TUI's `LaunchManagerExampleTest` pass. The getting-started page gets a note. _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
