refactor: move MyRouteBuilder to standalone class in java-lambda example#158
Merged
davsclaus merged 2 commits intoapache:mainfrom Mar 2, 2026
Merged
refactor: move MyRouteBuilder to standalone class in java-lambda example#158davsclaus merged 2 commits intoapache:mainfrom
davsclaus merged 2 commits intoapache:mainfrom
Conversation
Fixes IllegalAccessException during 'mvn camel:run' by ensuring the RouteBuilder is public and accessible for reflection.
davsclaus
requested changes
Mar 2, 2026
java-lambda/src/main/java/org/apache/camel/example/java8/MyRouteBuilder.java
Show resolved
Hide resolved
java-lambda/src/main/java/org/apache/camel/example/java8/MyRouteBuilder.java
Show resolved
Hide resolved
Contributor
Author
|
Hi @davsclaus , thank you for the review. I have updated the PR to include the ASF license header and fixed the indentation of the route to respect the EIP patterns as requested. I've also verified the fix again with mvn camel:run. |
davsclaus
approved these changes
Mar 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors the java-lambda example by moving the MyRouteBuilder inner class from MyApplication.java into its own standalone file, MyRouteBuilder.java.
The Problem:
Previously, MyRouteBuilder was defined as a package-private inner class. While mvn clean install passed (compilation was successful), running the example via mvn camel:run triggered a java.lang.IllegalAccessException.
This occurred because Apache Camel’s ObjectHelper uses reflection to instantiate routes. In modern Java runtimes (Java 17+), reflection-based access to non-public inner classes from a different package is restricted.
The Fix:
Created MyRouteBuilder.java as a public standalone class.
Removed the nested MyRouteBuilder class from MyApplication.java.
Verified that mvn camel:run now starts the Camel context successfully without reflection errors.